【Leetcode_easy】860. Lemonade Change

problem

860. Lemonade Change

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;

posted on 2019-07-19 18:15  鹅要长大  阅读(122)  评论(0编辑  收藏  举报

导航