leetcode209 长度最小的子数组
滑动窗口(双指针)
关键是如何对左右指针的值进行动态变化
var minSubArrayLen = function(target, nums) {
let left = 0;
let right = 0;
let sum = 0;
let minLen = Infinity;
while (right < nums.length) {
sum += nums[right];
while (sum >= target) {
minLen = Math.min(minLen, right - left + 1);
sum -= nums[left];
left++;
}
right++;
}
return minLen === Infinity ? 0 : minLen;
};