当前位置:网站首页>leetcode 209. 长度最小的子数组
leetcode 209. 长度最小的子数组
2022-07-22 10:17:00 【henujolly】
双指针
class Solution {
public:
int minSubArrayLen(int s, vector<int>& nums) {
int n = nums.size();
if (n == 0) {
return 0;
}
int l=0,r=0;
int sum=0,maxx=0x3f3f3f3f;
while(r<n){
sum+=nums[r];
while(sum>=s){
maxx=min(maxx,r-l+1);
sum-=nums[l];
l++;
}
r++;
}
if(maxx==0x3f3f3f3f) return 0;
else return maxx;
}
};
边栏推荐
猜你喜欢
system表空间用满解决
Data architecture and database modeling
IDEA运行WordCount程序(详细步骤)
Use of JVM jmap (memory mapping tool)
Jiayuan "great earthquake" of the century
Spark GraphX 中的 pregel函数(转载)
Install MariaDB 10.5.7 (tar package installation)
从数据标准到数据库设计:解决基础数据标准落地的最后一公里难题(下)
Typora下载和简单使用教程
MySQL converts milliseconds into time string
随机推荐
oracle怎样转义单引号
Data architecture and database modeling
nacos权限与数据库
最佳实践|用腾讯云AI文字识别实现企业资质证书识别
Neo4j example: figure relationship map of the annals of the Three Kingdoms
mysql grant 用户权限总结
HTB- Armageddon
C语言程序设计代码
Structure, enumeration, joint blog tutorial
Mysql之一主多从复制
ZABBIX realizes nail monitoring alarm
Typora下载和简单使用教程
AForge "failed to load the file or assembly" aforge.video.ffmpeg.dll "or one of its dependencies. The specified module cannot be found "
Dynamic memory management and flexible array
The luckiest geek in China: in his early twenties, he was worth more than 100 million, and retired after three startups
Vs Code common shortcut keys
Atr5179 single pole double throw switch chip replaces as179-92lf
数据仓库模型设计与工具
ES6新特性分享(三)
发现mariadb数据库时间晚了12个小时,xxljob定时任务调度异常