We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e213706 commit 9bf9e05Copy full SHA for 9bf9e05
Lemonade Change/solution.java
@@ -0,0 +1,29 @@
1
+class Solution {
2
+ public boolean lemonadeChange(int[] bills) {
3
+ int five_dollars = 0, ten_dollars = 0;
4
+
5
+ for (int x : bills) {
6
+ if (x == 5) {
7
+ five_dollars++;
8
+ } else if (x == 10) {
9
+ if (five_dollars > 0) {
10
+ five_dollars--;
11
+ ten_dollars++;
12
+ } else {
13
+ return false;
14
+ }
15
16
+ if (five_dollars > 0 && ten_dollars > 0) {
17
18
+ ten_dollars--;
19
+ } else if (five_dollars > 2) {
20
+ five_dollars -= 3;
21
22
23
24
25
26
27
+ return true;
28
29
+}
0 commit comments