上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 23 下一页
摘要: class Solution { public: bool checkPossibility(vector<int>& nums) { vector<int> res; int count = 0; for(int i = 0; i < nums.size()-1; i++){ if(nums[i] 阅读全文
posted @ 2021-08-09 19:58 三一一一317 阅读(30) 评论(0) 推荐(0)
摘要: class Solution { public: static bool cmp(vector<int> &a, vector<int> &b){ if(a[0] != b[0]) // 第一个元素不等,先按照第一个元素从大到小排序 return a[0]>b[0]; else return a[1 阅读全文
posted @ 2021-08-09 17:03 三一一一317 阅读(23) 评论(0) 推荐(0)
摘要: 这题可以用动态规划。 题目中指出:注意:你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。但是没有没有提及 同一天不能发生两笔交易 因此可以用贪心算法。因为贪心算法中同一天先卖出后买入。 class Solution { public: int maxProfit(vector<int> 阅读全文
posted @ 2021-08-09 16:24 三一一一317 阅读(25) 评论(0) 推荐(0)
摘要: class Solution { public: vector<int> partitionLabels(string s) { vector<int> res; int map[26]; for(int i = 0; i < s.length(); i++){ map[s[i]-'a'] = i; 阅读全文
posted @ 2021-08-09 15:59 三一一一317 阅读(20) 评论(0) 推荐(0)
摘要: class Solution { public: static bool cmp(vector<int> &a, vector<int> &b){ return a[1]<b[1]; } int findMinArrowShots(vector<vector<int>>& points) { // 阅读全文
posted @ 2021-08-09 15:15 三一一一317 阅读(29) 评论(0) 推荐(0)
摘要: class Solution { public: bool canPlaceFlowers(vector<int>& flowerbed, int n) { int count = 0; int len = flowerbed.size(); // 针对长度为0的情况 if(len==0) retu 阅读全文
posted @ 2021-08-09 14:49 三一一一317 阅读(32) 评论(0) 推荐(0)
摘要: class Solution { public: // 注意必须加上&符号,不然超时报错,因为加引用是地址传递, // 不加会创建一个新的变量,和原来的变量指向同一个地址 static int cmp(vector<int> &a, vector<int> &b){ return a[1]<b[1] 阅读全文
posted @ 2021-08-09 12:49 三一一一317 阅读(28) 评论(0) 推荐(0)
摘要: 这题作者的想法太简洁了,涉及好多细节,一般人想不到。 class Solution { public: string decodeString(string s) { stack<pair<int, string>> st; int num = 0; string res = ""; for(int 阅读全文
posted @ 2021-07-29 11:25 三一一一317 阅读(19) 评论(0) 推荐(0)
摘要: class Solution { public: static int cmp(vector<int> a, vector<int> b){ if(a[0] != b[0]) // 第一个元素不相等,按照从大到小排序, return a[0]>b[0]; else // 第一个元素相等,第二个元素按 阅读全文
posted @ 2021-07-28 15:45 三一一一317 阅读(23) 评论(0) 推荐(0)
摘要: class Solution { public: bool canPartition(vector<int>& nums) { int n = nums.size(); if(n<=1) // 数组长度小于等于1返回false return false; int sum = 0; for(int i 阅读全文
posted @ 2021-07-28 15:01 三一一一317 阅读(33) 评论(0) 推荐(0)
上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 23 下一页