1、题目
https://leetcode-cn.com/problems/lemonade-change/
2、题意
题解1:简单贪心,先用10元的。
class Solution {
public:
bool lemonadeChange(vector<int>& bills) {
int cnt5 = 0,cnt10 = 0;
for(int i=0;i<bills.size();i++)
{
if(bills[i]==5)
cnt5++;
else if(bills[i]==10)
{
cnt10++;
cnt5--;
}
else
{
int need = 15;
if(cnt10)
{
cnt10--;
need-=10;
}
cnt5-=need/5;
}
if(cnt5<0)
return false;
}
return true;
}
};