-
860.柠檬水找零
-
class Solution { public: bool lemonadeChange(vector<int>& bills) { int w = 0, s = 0, e = 0; for (int i = 0; i < bills.size(); i++) { if (bills[i] == 5) { w++; } else if (bills[i] == 10) { if (w > 0) { s++; w--; } else return 0; } else { if (w > 0 && s > 0) { s--; w--; e++; } else if (w >= 3) { w -= 3; } else return 0; } } return 1; } };
-
406.根据身高重建队列
-
class Solution { public: static bool cmp(const vector<int>& a, const vector<int>& b) { if (a[0] == b[0]) return a[1] < b[1]; return b[0] < a[0]; } vector<vector<int>> reconstructQueue(vector<vector<int>>& people) { sort(people.begin(), people.end(), cmp); vector<vector<int>> ret; for (int i = 0; i < people.size(); i++) { ret.insert(ret.begin() + people[i][1], people[i]); } return ret; } };
-
452. 用最少数量的箭引爆气球
-
class Solution { public: static bool cmp(vector<int>& a,vector<int>& b){ return a[0]<b[0]; } int findMinArrowShots(vector<vector<int>>& points) { sort(points.begin(),points.end(),cmp); int ans=1; int r=points[0][1]; for(int i=1;i<points.size();i++){ if(r<=points[i][1]){ ans++; r=points[i][1]; } } return ans; } };