摘要: class Solution { public: int minSubArrayLen(int target, vector<int>& nums) { int sum[100010]={0}; int n=nums.size(); for(int i=1;i<=n;++i) { sum[i]=su 阅读全文
posted @ 2022-02-05 18:03 Jerry2km1 阅读(53) 评论(0) 推荐(0)
摘要: class Solution{ public: vector<vector<int>> threeSum(vector<int>& nums) { sort(nums.begin(),nums.end()); vector<vector<int>> ans; for(int k=0;k<nums.s 阅读全文
posted @ 2022-02-05 17:50 Jerry2km1 阅读(36) 评论(0) 推荐(0)
摘要: class Solution { public: vector<int> twoSum(vector<int>& numbers, int target) { int length=numbers.size(); int left,right,cpl=length-1,m; int flag=0; 阅读全文
posted @ 2022-02-05 17:11 Jerry2km1 阅读(48) 评论(0) 推荐(0)
摘要: class Solution { public: int maxProduct(vector<string>& words) { int n = words.size(); int stat[n]; int wsize[n]; //存储单词长度 for(int i=0 ; i<n ; i++) { 阅读全文
posted @ 2022-02-05 17:07 Jerry2km1 阅读(46) 评论(0) 推荐(0)
摘要: class Solution { public: int singleNumber(vector<int>& nums) { int ans = 0; int total = 0; for(int i = 0; i<32 ; ++i) { total = 0; for(int j=0; j<nums 阅读全文
posted @ 2022-02-05 17:05 Jerry2km1 阅读(40) 评论(0) 推荐(0)
摘要: 解题思路 由于是求最短子串,很容易联想到使用滑动窗口去解决问题。可以按寻找合法子串->缩短子串->滑动窗口移动的思路进行解题。(1)寻找合法子串:不使用哈希表,map等数据结构,而是使用三个计数数组。ct1统计s中字符出现次数,ct2统计t中字符出现次数,ct3标记“有效的包含”,其对单个字符进行统 阅读全文
posted @ 2022-01-31 16:18 Jerry2km1 阅读(167) 评论(0) 推荐(0)
摘要: 1 class Solution { 2 public: 3 string subStrHash(string s, int p, int m, int k, int hash) { 4 int n = s.size(); 5 unsigned long long pow[20010]; //lon 阅读全文
posted @ 2022-01-30 16:02 Jerry2km1 阅读(85) 评论(0) 推荐(0)
摘要: 1 class Solution { 2 public: 3 vector<int> countBits(int n) { 4 vector<int> ct(n+1,0); 5 for(int i=1;i<=n;++i) 6 { 7 ct[i]=ct[i>>1]+(i&1); //当为奇数时,结果为 阅读全文
posted @ 2022-01-25 11:37 Jerry2km1 阅读(34) 评论(0) 推荐(0)
摘要: 1 class Solution { 2 public: 3 int divide(int a,int b) { 4 if (b == -1) 5 { 6 if(a == INT_MIN) 7 return INT_MAX; 8 return -a; 9 } 10 if (a!=INT_MIN && 阅读全文
posted @ 2022-01-20 08:45 Jerry2km1 阅读(62) 评论(0) 推荐(0)