摘要: 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 阅读(41) 评论(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 阅读(36) 评论(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 阅读(32) 评论(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 阅读(19) 评论(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 阅读(43) 评论(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 阅读(40) 评论(0) 推荐(0)
摘要: class Solution { public: bool searchMatrix(vector<vector<int>>& matrix, int target) { int i = matrix.size()-1; int j = 0; while(i>=0&&j<matrix[0].size 阅读全文
posted @ 2021-07-24 13:57 三一一一317 阅读(31) 评论(0) 推荐(0)
摘要: class Solution { public: vector<int> maxSlidingWindow(vector<int>& nums, int k) { priority_queue<pair<int ,int>> q; vector<int> res; //规则:pair的比较,先比较第 阅读全文
posted @ 2021-07-24 13:40 三一一一317 阅读(46) 评论(0) 推荐(0)
摘要: class Solution { public: vector<int> productExceptSelf(vector<int>& nums) { if(nums.size()==0) return {}; vector<int> a(nums.size(),1); vector<int> b( 阅读全文
posted @ 2021-07-24 11:26 三一一一317 阅读(43) 评论(0) 推荐(0)
摘要: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : 阅读全文
posted @ 2021-07-24 11:13 三一一一317 阅读(35) 评论(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-24 10:34 三一一一317 阅读(26) 评论(0) 推荐(0)