[LeetCode]长度最小的子数组
题目
代码
class Solution {
public:
int minSubArrayLen(int s, vector<int>& nums) {
if(nums.empty())
return 0;
int start=0,end=0,size=nums.size(),sum=nums[0],record=INT_MAX;
while(start<size)
{
while(sum<s)
{
end++;
if(end==size)
return record==INT_MAX?0:record;
sum+=nums[end];
}
record=min(record,end-start+1);
sum-=nums[start];
start++;
}
return record;
}
};
https://github.com/li-zheng-hao