209. Minimum Size Subarray Sum
202410042223
tags: #sliding-window
var minSubArrayLen = function(target, nums) {
let start = 0;
let end = 0;
let res = Number.POSITIVE_INFINITY;
let curSum = 0;
while (end < nums.length) {
curSum += nums[end];
end += 1;
while (start < end && curSum >= target) {
res = Math.min(res, end - start);
curSum -= nums[start];
start += 1;
}
}
return res === Number.POSITIVE_INFINITY ? 0 : res;
};