• 문제 링크
Lemonade Change - LeetCode
Can you solve this real interview question? Lemonade Change - At a lemonade stand, each lemonade costs $5. Customers are standing in a queue to buy from you and order one at a time (in the order specified by bills). Each customer will only buy one lemonade
leetcode.com
• 풀이 코드
public class Solution {
public boolean lemonadeChange(int[] bills) {
int f = 0, t = 0;
for (int i : bills) {
if (i == 5) {
f++;
} else if (i == 10) {
if (f == 0) return false;
f--;
t++;
} else {
if (f > 0 && t > 0) {
f--;
t--;
} else if (f >= 3) f -= 3;
else return false;
}
}
return true;
}
}'Problem Solving > LeetCode' 카테고리의 다른 글
| [LeetCode] 868. Binary Gap - Java (0) | 2026.10.29 |
|---|---|
| [LeetCode] 867. Transpose Matrix - Java (0) | 2026.10.28 |
| [LeetCode] 859. Buddy Strings - Java (0) | 2026.10.26 |
| [LeetCode] 844. Backspace String Compare - Java (0) | 2026.10.25 |
| [LeetCode] 836. Rectangle Overlap - Java (0) | 2026.10.24 |
댓글