class Solution {
public int minSubArrayLen(int target, int[] nums) {
int res = nums.length,flag = 0;
int sum = 0;
int i=0;
//确定滑动窗口的尾部
for(int j=0;j<nums.length;j++){
sum+=nums[j];
while(sum>=target){
res = Math.min(j-i+1,res);
//找到合适的值后,尝试缩小i的范围
//缩小之后不满足条件了,移动j的范围
sum-=nums[i++];
flag = 1;
}
}
if(flag==0) return 0;
return res;
}
}