class Solution {
public:
int minSubArrayLen(int target, vector<int>& nums) {
int n=nums.size();
int sum=0;
int minlen=n+1;
int l=0;
if(n==0){
return 0;
}
for(int i=0;i<n;i++){
sum+=nums[i];
while(sum>=target && l<=i){
minlen=min(minlen,i-l+1);
sum-=nums[l];
l+=1;
}
}
return minlen==n+1?0:minlen;
}
};
LEETCODE 209. 长度最小的子数组
最新推荐文章于 2024-11-04 12:20:00 发布