上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 23 下一页
摘要: class Solution { public: int findUnsortedSubarray(vector<int>& nums) { // 笨方法,先排序,再从两端进行比较 int i = 0; int j = nums.size()-1; vector<int> res(nums.size 阅读全文
posted @ 2021-07-25 12:52 三一一一317 阅读(57) 评论(0) 推荐(0)
摘要: /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), rig 阅读全文
posted @ 2021-07-25 11:55 三一一一317 阅读(20) 评论(0) 推荐(0)
摘要: class Solution { public: int countSubstrings(string s) { // 中心扩展法 // 注意回文中心可能是一个,也可能是两个 // 如果aba 有中心a向两边扩展, abba右bb向两边分别扩展得到。 int res = 0; for(int i = 阅读全文
posted @ 2021-07-25 11:30 三一一一317 阅读(27) 评论(0) 推荐(0)
摘要: // class Solution { // public: // vector<int> dailyTemperatures(vector<int>& temperatures) { // vector<int> dp(temperatures.size(), 0); // // 这个是求最长子序 阅读全文
posted @ 2021-07-25 11:09 三一一一317 阅读(27) 评论(0) 推荐(0)
摘要: class Solution { public: vector<int> countBits(int n) { vector<int> res; int temp = 0; for(int i = 0; i <=n;i++){ temp = countone(i); res.push_back(te 阅读全文
posted @ 2021-07-24 19:19 三一一一317 阅读(30) 评论(0) 推荐(0)
摘要: class Solution { public: int lengthOfLIS(vector<int>& nums) { vector<int> dp(nums.size(), 1); // dp[0] = 1; // dp[i] 0~i范围内的最长递增子序列。 for(int i = 1; i 阅读全文
posted @ 2021-07-24 15:57 三一一一317 阅读(25) 评论(0) 推荐(0)
摘要: class Solution { public: int findDuplicate(vector<int>& nums) { unordered_map<int, int> in_map; for(int i =0; i < nums.size(); i++){ in_map[nums[i]]++ 阅读全文
posted @ 2021-07-24 15:29 三一一一317 阅读(21) 评论(0) 推荐(0)
摘要: class Solution { public: /* 这里我们可以用第一个0当做这个中间点, 把不等于0(注意题目没说不能有负数)的放到中间点的左边,等于0的放到其右边。 */ void moveZeroes(vector<int>& nums) { int j = 0; // j 指向第一个0 阅读全文
posted @ 2021-07-24 15:23 三一一一317 阅读(17) 评论(0) 推荐(0)
摘要: class Solution { public: int numSquares(int n) { vector<int> dp(n+1,0); for(int i = 1; i <= n;i++){ dp[i] = i; //最差情况,有i个1组成, for(int j = 1; i-j*j>=0; 阅读全文
posted @ 2021-07-24 15:04 三一一一317 阅读(32) 评论(0) 推荐(0)
摘要: /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), r 阅读全文
posted @ 2021-07-24 14:39 三一一一317 阅读(27) 评论(0) 推荐(0)
上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 23 下一页