-
-
Notifications
You must be signed in to change notification settings - Fork 610
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sherali Obidov
committed
Aug 16, 2018
1 parent
5eba62a
commit 29ea919
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package problems.easy; | ||
|
||
/** | ||
* Why Did you create this class? what does it do? | ||
*/ | ||
public class LemonadeChange { | ||
public boolean lemonadeChange(int[] bills) { | ||
int[] a = new int[3]; | ||
for (int i = 0; i < bills.length; i++) { | ||
if (bills[i] == 5) { | ||
a[0]++; | ||
continue; | ||
} else if (bills[i] == 10) { | ||
a[1]++; | ||
a[0]--; | ||
if (a[0] < 0) | ||
return false; | ||
} else { | ||
a[2]++; | ||
if (a[0] < 1) | ||
return false; | ||
a[0]--; | ||
if (a[1] > 0) { | ||
a[1]--; | ||
} else { | ||
a[0] -= 2; | ||
if (a[0] < 0) | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
} |