Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- bool lemonadeChange(vector<int>& bills) {
- int x20 = 0, x10 = 0, x5 = 0;
- for (auto b: bills) {
- if (b == 20) {
- // Try 10, 5; then 5, 5, 5
- if (x10 && x5) {
- x10--;
- x5--;
- }
- else if (x5 >= 3) {
- x5 -= 3;
- }
- else {
- return false;
- }
- x20++;
- }
- else if (b == 10) {
- if (x5) {
- x5--;
- }
- else {
- return false;
- }
- x10++;
- }
- else {
- x5++;
- }
- }
- return true;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement