随笔分类 -  LeetCode

摘要:v初始化为只有空集的vector 遍历nums容器中的元素,每次扩容v为原先的两倍并将后一半子集每个都加上nums[i] 阅读全文
posted @ 2022-05-10 10:16 智人心 阅读(16) 评论(0) 推荐(0) 编辑
摘要:kase从1开始自增,n每次减去kase,当n减到负数的时候,kase-2即为所求 阅读全文
posted @ 2022-05-10 09:35 智人心 阅读(5) 评论(0) 推荐(0) 编辑
摘要:利用二进制数的特性,每逢2的幂1的个数退回1,并且与之前的计算有着差1的关系,即: a[i] = a[i-kase/2]+1; 阅读全文
posted @ 2022-05-09 20:15 智人心 阅读(15) 评论(0) 推荐(0) 编辑
摘要:令min = 0,max = n, 从0到n-1扫描s,如果s[i]是I就令结果vector添加一个元素min并令min++ 如果s[i]是D就令结果vector添加一个元素max并令max-- 最后添加一个元素min或者max(min==max) 阅读全文
posted @ 2022-05-09 19:36 智人心 阅读(17) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: bool isMatch(string s, string p) { memset(dp,false,sizeof(dp)); int ns = s.size(),np = p.size(); bool flag; for(int i=1;i<ns; 阅读全文
posted @ 2022-01-06 17:24 智人心 阅读(31) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector<vector<int>> combinationSum(vector<int>& candidates, int target) { sort(candidates.begin(),candidates.end()); vector<v 阅读全文
posted @ 2022-01-05 17:07 智人心 阅读(23) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: void solveSudoku(vector<vector<char>>& board) { for(int i=0;i<9;i++){ for(int j=0;j<9;j++){ if(board[i][j]!='.'){ mt[0][i][bo 阅读全文
posted @ 2022-01-03 21:28 智人心 阅读(23) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int longestValidParentheses(string s) { int n = s.size(),i = 0,maxResult = 0,result = 0,t,tmax,tsum; if(n==0)return 0; stack< 阅读全文
posted @ 2022-01-02 19:57 智人心 阅读(25) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector<int> findSubstring(string s, vector<string>& words) { vector<int>v; string t; int n = s.size(),n2 = words.size(),n3 = 阅读全文
posted @ 2022-01-02 15:30 智人心 阅读(19) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector<vector<int>> threeSum(vector<int>& nums) { vector<vector<int>>v; vector<int>v2; sort(nums.begin(),nums.end()); int n = 阅读全文
posted @ 2021-12-30 14:50 智人心 阅读(19) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int maxArea(vector<int>& height) { int i = 0,j = height.size()-1,result = 0; while(i<j){ int h = min(height[i],height[j]); re 阅读全文
posted @ 2021-12-30 09:37 智人心 阅读(18) 评论(0) 推荐(0) 编辑
摘要:double findMedianSortedArrays(int* nums1, int nums1Size, int* nums2, int nums2Size){ int i = 0,p = 0,q = 0,n1 = nums1Size+nums2Size,n = (nums1Size+num 阅读全文
posted @ 2021-12-29 17:56 智人心 阅读(18) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示