滑动窗口!!
class Solution {
public:
int minSubArrayLen(int target, vector<int>& nums) {
int left = 0, right = 0, sum = nums[0];
int minLength = INT_MAX;
while(left <= right && right < nums.size()){
if(sum >= target){
if(minLength > right - left + 1) minLength = right - left + 1;
sum -= nums[left++];
}else{
if(right == nums.size() - 1) break;
sum += nums[++right];
}
}
if(minLength == INT_MAX) minLength = 0;
return minLength;
}
};
标签:right,nums,209,minLength,sum,int,数组,长度,left From: https://www.cnblogs.com/llllmz/p/18407398