双指针,start和end之间维护一段>=s的数列,
class Solution {
public:
int minSubArrayLen(int s, vector<int>& nums) {
int n=nums.size();
int sum=0,start=0,end=0;
int m=n+1;
while(end<n)
{
while(end<n&&sum<s)
{
sum+=nums[end++];
}
while(sum>=s&&start<=end)
{
m=min(end-start,m);
sum-=nums[start++];
}
}
if(m==n+1)
return 0;
return m;
}
};