随笔分类 -  第二期Week3——贪心专题

摘要:1 class Solution 2 { 3 public: 4 string removeKdigits(string num, int k) 5 { 6 if(num.size() == k) return "0"; 7 stack<char> stk;//单调栈 8 string res; 9 阅读全文
posted @ 2020-04-18 21:31 Jinxiaobo0509 阅读(103) 评论(0) 推荐(0)
摘要:1 bool cmp(vector<int>& a,vector<int>& b) 2 { 3 //第一个数从小到大排列 如果第一个数相等,则第二个数从小到大排列 4 return a[0] < b[0] || ((a[0] == b[0]) && (a[1] < b[1])); 5 } 6 7 c 阅读全文
posted @ 2020-04-18 17:11 Jinxiaobo0509 阅读(120) 评论(0) 推荐(0)
摘要:1 bool cmp(vector<int>& a,vector<int>& b) 2 { 3 //第一个数从大到小排列 如果第一个数相等,则第二个数从小到大排列 4 return a[0] > b[0] || ((a[0] == b[0]) && (a[1] < b[1])); 5 } 6 7 c 阅读全文
posted @ 2020-04-18 16:47 Jinxiaobo0509 阅读(115) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 public: 4 int wiggleMaxLength(vector<int>& nums) 5 { 6 //删除相邻且相同的元素 7 nums.erase(unique(nums.begin(),nums.end()),nums.end()); 8 阅读全文
posted @ 2020-04-18 16:03 Jinxiaobo0509 阅读(94) 评论(0) 推荐(0)
摘要:1 //BFS + 贪心 2 //维护一个区间[l,r],在这里面可以找到能够跳到最大位置,step++,同时更新l,r 3 class Solution 4 { 5 public: 6 int jump(vector<int>& nums) 7 { 8 if(nums.size() < 2) re 阅读全文
posted @ 2020-04-18 14:57 Jinxiaobo0509 阅读(90) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 public: 4 int findContentChildren(vector<int>& g, vector<int>& s) 5 { 6 sort(g.rbegin(),g.rend()); 7 sort(s.rbegin(),s.rend()); 阅读全文
posted @ 2020-04-18 11:24 Jinxiaobo0509 阅读(69) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 public: 4 bool isSubsequence(string s, string t) 5 { 6 int n = s.size(); 7 int i = 0; 8 for(int j = 0;j < t.size();j ++) 9 { 10 阅读全文
posted @ 2020-04-18 11:06 Jinxiaobo0509 阅读(105) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 public: 4 bool lemonadeChange(vector<int>& bills) 5 { 6 unordered_map<int,int> hash; 7 for(auto a : bills) 8 { 9 if(a == 5) has 阅读全文
posted @ 2020-04-18 10:37 Jinxiaobo0509 阅读(147) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 public: 4 int canCompleteCircuit(vector<int>& gas, vector<int>& cost) 5 { 6 int n = gas.size(); 7 for(int i = 0;i < n;i ++) 8 { 阅读全文
posted @ 2020-04-02 13:42 Jinxiaobo0509 阅读(109) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 public: 4 bool canJump(vector<int>& nums) 5 { 6 int n = nums.size(); 7 int max_size = nums[0]; 8 for(int i = 0;i < n;i ++) 9 { 阅读全文
posted @ 2020-03-19 18:07 Jinxiaobo0509 阅读(96) 评论(0) 推荐(0)