会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
wangkaixin-yy
博客园
首页
新随笔
联系
订阅
管理
上一页
1
···
3
4
5
6
7
8
9
10
下一页
2023年5月29日
leetcode1657vector的初始化和比较
摘要: 满足相似的条件:1.长度一样 2.组成的字母组合相同 3.每个组成字母的个数集合相同 比较两个vector,直接用==/!= 排序vector sort(迭代器1,迭代器2); 初始化vector形式:vector<类型>name(形式) if(word1.lenth()!=word2.length
阅读全文
posted @ 2023-05-29 16:37 iu本u
阅读(20)
评论(0)
推荐(0)
2023年5月24日
leetcode1207哈希表的操作和count的操作
摘要: 哈希表初始化有unordered_map<int,int>map或map<int,int>m 他们都是不存储重复的键 map[key]=value Vector::count(): count(v.begin(),v.end(),target)
阅读全文
posted @ 2023-05-24 13:59 iu本u
阅读(80)
评论(0)
推荐(0)
2023年5月23日
leetcode2215哈希列表的应用
摘要: 哈希列表存储的是不重复的元素,使用两个哈希列表存储这两个数组。再遍历其中一个哈希列表,查看是否存在另一个哈希列表中 set.insert() set1.count(元素) for(int num:nums1){ set1.insert(num); } for(int num:set1){ if(!s
阅读全文
posted @ 2023-05-23 17:06 iu本u
阅读(13)
评论(0)
推荐(0)
2023年5月21日
leetcode724
摘要: 使用数学方法: 假设左边的所有数加起来的和是sum,total为数组所有元素加起来的和,当i满足中心下标的条件时,即: sum=total-sum-nums[i]; 2*sum+nums[i]=total; 当中心下标是首位时,即左边sum为0;当中心下标是尾位时,右边total-sum-nums[
阅读全文
posted @ 2023-05-21 19:48 iu本u
阅读(14)
评论(0)
推荐(0)
2023年5月20日
leetcode1493
摘要: 递归: 1.记pre[i]为以i位置结尾的连续1长度。 pre[i]=0;ai=0 pre[i]=pre[i-1]+1;ai=1 记suf[i]为以位置i开头的连续1长度; suf[i]=0;ai=0 suf[i]=suf[i+1]+1;ai=1 计算删掉i位置的连续1的长度为pre[i-1]+su
阅读全文
posted @ 2023-05-20 20:05 iu本u
阅读(22)
评论(0)
推荐(0)
2023年5月14日
leetcode1004
摘要: 1.二分查找法 用一数组P【i】记录每个位置之前到自己本身位置i有多少个0,只要满足【left,ridht】之间的0个数小于等于k就可以连接成为连续的1。 即P【上界】-P【下界】<=k,枚举right,则要找到最小left就能够找到最长的连续1,P[right]-k<=P[left],则最小的le
阅读全文
posted @ 2023-05-14 22:13 iu本u
阅读(24)
评论(0)
推荐(0)
upper_bound和lower_bound的二分查找底层实现
摘要: lower_bound(下界,上界,目标值)找到不小于目标值的位置,即大于等于 while(left<right){ int mid=left+(right-left)/2;//查找区间[left,right) if(target<nums[mid]){ left=mid+1; }else{ rig
阅读全文
posted @ 2023-05-14 21:31 iu本u
阅读(39)
评论(0)
推荐(0)
2023年5月13日
vector和string的转化
摘要: C99:int数字_t,t表示它是取另一个名字,不是新的数据类型 uint数字_t表示无符号,编译器把这种数据类型看成数字。 数字是指单位长度有多少bit 1.string转vector<char> 用assign string与数字转化 string s=“helllo word!” vector
阅读全文
posted @ 2023-05-13 19:06 iu本u
阅读(651)
评论(0)
推荐(0)
2023年5月10日
leetcode643
摘要: 滑动窗口: 利用一个变量记录nums[k-1]之后位置的k长度子数组的总和,再用一个变量记录最大值,与最大就调换。 起初开辟的是一个vector容器去存,改为用一个变量最好 for(int i=0;i<k;i++){ sum+=nums[i]; } for(int i=k;i<n;i++){ sum
阅读全文
posted @ 2023-05-10 19:30 iu本u
阅读(15)
评论(0)
推荐(0)
2023年5月9日
leetcode 1679
摘要: 1.排序双指针 先排序 sort(nums.begin(),nums.end()); 在双指针查找 while(left<right){ if(nums[left]+nums[right]<k){ left++; }else if(nums[left]+nums[right]>k){ right--
阅读全文
posted @ 2023-05-09 17:00 iu本u
阅读(19)
评论(0)
推荐(0)
上一页
1
···
3
4
5
6
7
8
9
10
下一页
公告