leetcode算法题--Lemonade Change
作者:互联网
原题链接:https://leetcode.com/problems/lemonade-change/
bool lemonadeChange(vector<int>& bills) {
int tens = 0, fives = 0;
for (auto x : bills) {
if (x == 5) {
fives ++ ;
} else if (x == 10) {
if (fives) {
fives -- ;
tens ++ ;
} else {
return false;
}
} else if (x == 20) {
int t = 15;
if (tens) {
tens -- ;
t -= 10;
}
while (t && fives) {
fives -- ;
t -= 5;
}
if (t) {
return false;
}
}
}
return true;
}
标签:return,fives,--,Lemonade,else,tens,false,leetcode 来源: https://blog.csdn.net/qq_20817327/article/details/118501067