摘要: class Solution { public: int climbStairs(int n) { vector<int> dp(n+1,0); if(n<2) return n; dp[0] = 0; dp[1] = 1; dp[2] = 2; // dp[i] 定义:到达当前i阶有dp[i]种不 阅读全文
posted @ 2021-07-16 20:54 三一一一317 阅读(23) 评论(0) 推荐(0)
摘要: 直接想到动态规划 class Solution { public: int maxSubArray(vector<int>& nums) { vector<int> dp(nums.size(),0); dp[0] = nums[0]; for(int i = 1; i < nums.size(); 阅读全文
posted @ 2021-07-16 20:43 三一一一317 阅读(35) 评论(0) 推荐(0)
摘要: class Solution { public: static bool cmp(string a, string b){ int sum_a = 0; int sum_b = 0; sort(a.begin(), a.end()); sort(b.begin(), b.end()); return 阅读全文
posted @ 2021-07-16 20:06 三一一一317 阅读(31) 评论(0) 推荐(0)
摘要: class Solution { public: void rotate(vector<vector<int>>& matrix) { int len = matrix.size(); // 先转化为对成矩阵 for(int i = 0; i < len;i++) for(int j = 0; j< 阅读全文
posted @ 2021-07-16 17:35 三一一一317 阅读(23) 评论(0) 推荐(0)
摘要: 39题组合总数也可以用这种模式 class Solution { public: vector<vector<int>> res; vector<vector<int>> permute(vector<int>& nums) { if(nums.size()==0) return res; vect 阅读全文
posted @ 2021-07-16 17:20 三一一一317 阅读(21) 评论(0) 推荐(0)
摘要: 解析参见: https://leetcode-cn.com/problems/trapping-rain-water/solution/jie-yu-shui-by-leetcode/327718/ class Solution { public: int trap(vector<int>& hei 阅读全文
posted @ 2021-07-16 16:04 三一一一317 阅读(35) 评论(0) 推荐(0)
摘要: 看到此题回想到用回溯法枚举可能的情况。 class Solution { public: vector<vector<int>> res; vector<vector<int>> combinationSum(vector<int>& candidates, int target) { if(can 阅读全文
posted @ 2021-07-16 15:07 三一一一317 阅读(22) 评论(0) 推荐(0)
摘要: class Solution { public: vector<int> searchRange(vector<int>& nums, int target) { vector<int> res; int left = lcoateleft(nums,0,nums.size()-1,target); 阅读全文
posted @ 2021-07-16 13:41 三一一一317 阅读(35) 评论(0) 推荐(0)
摘要: class Solution { public: int search(vector<int>& nums, int target) { int len = nums.size(); // if(len<2) // return 0; int left = 0; int right = len-1; 阅读全文
posted @ 2021-07-16 13:03 三一一一317 阅读(27) 评论(0) 推荐(0)