860.柠檬水找零
思路:
遇到20,先给10和5,再给三个5代码:
1 bool lemonadeChange(vector<int>& bills) { 2 if (bills.size() == 0) return true; 3 4 map<int, int> currentMoney; 5 for (int i = 0; i < bills.size(); i++) 6 { 7 if (bills[i] == 5) 8 { 9 currentMoney[5]++; 10 } 11 else if (bills[i] == 10) 12 { 13 if (currentMoney[5] < 1) 14 { 15 return false; 16 } 17 18 currentMoney[5]--; 19 currentMoney[10]++; 20 } 21 else if (bills[i] == 20) 22 { 23 if (currentMoney[5] >= 1 && currentMoney[10] >= 1) 24 { 25 currentMoney[5]--; 26 currentMoney[10]--; 27 } 28 else if (currentMoney[5] >= 3) { 29 currentMoney[5] = currentMoney[5] - 3; 30 } 31 else 32 { 33 return false; 34 } 35 } 36 } 37 38 return true; 39 }
标签:20,10,return,随想录,取反,else,135,currentMoney,bills From: https://www.cnblogs.com/smartisn/p/17544208.html