Created
July 17, 2025 16:19
-
-
Save langolf/81a66ff21a19d4070df63d68afce4693 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number[]} bills | |
* @return {boolean} | |
*/ | |
var lemonadeChange = function (bills) { | |
let tens = 0; | |
let fiths = 0; | |
while (bills.length) { | |
const client = bills.shift(); | |
if (client === 5) { | |
fiths += 5; | |
} | |
if (client === 10) { | |
if (fiths > 0) { | |
fiths -= 5; | |
tens += 10; | |
} else { | |
return false; | |
} | |
} | |
if (client === 20) { | |
if (tens > 0 && fiths > 0) { | |
tens -= 10; | |
fiths -= 5; | |
} else if (tens === 0 && fiths > 10) { | |
fiths -= 15; | |
} else { | |
return false; | |
} | |
} | |
} | |
return true; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment