1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| class Solution { public: bool lemonadeChange(vector<int>& bills) {\ int five = 0, ten = 0; for (int bill : bills) { if (bill == 5) { ++five; } else if (bill == 10) { if (--five < 0) return false; ++ten; } else { if (five > 0 && ten > 0) { --five; --ten; } else if (five >= 3) { five -= 3; } else { return false; } } } return true; } };
|