problem
solution
class Solution { public: bool lemonadeChange(vector<int>& bills) { int five = 0, ten = 0; for(auto bill:bills) { if(bill==5) five++; else if(bill==10) { ten++; five--; } else if(ten>0) { ten--; five--; } else five -= 3; if(five<0) return false; } return true; } };
参考
1. Leetcode_easy_860. Lemonade Change;
2. Discuss;
3. Grandyang;
完