摘要: LeetCode 435. Non-overlapping Intervals 贪心 按照有边界排序,只有先选择了右边边界小的,才可以放下更多的区间 class Solution { public: int eraseOverlapIntervals(vector<vector<int>>& intervals) { if(intervals.empty()) return 0 阅读全文
posted @ 2022-11-08 19:30 破忒头头 阅读(25) 评论(0) 推荐(0)
摘要: LeetCode 135. Candy 贪心算法 贪心策略:在每次遍历中,仅考虑并更新相邻一侧的大小关系 class Solution { public: int candy(vector<int>& ratings) { int size = ratings.size(); if(size<2){ return size; } vect 阅读全文
posted @ 2022-11-08 19:04 破忒头头 阅读(26) 评论(0) 推荐(0)
摘要: 贪心 class Solution { public: int findContentChildren(vector<int>& g, vector<int>& s) { sort(g.begin(),g.end()); sort(s.begin(),s.end()); int cd=0; int 阅读全文
posted @ 2022-11-08 19:04 破忒头头 阅读(22) 评论(0) 推荐(0)
摘要: #二分法 class Solution { public: int searchInsert(vector<int>& nums, int target) { int l = 0; int r = nums.size()-1; while(l<=r){ int mid = (l + r)/2; if 阅读全文
posted @ 2022-11-08 17:25 破忒头头 阅读(15) 评论(0) 推荐(0)