一、题目地址
https://leetcode-cn.com/problems/2VG8Kg/
二、具体代码
/**
* @param {number} target
* @param {number[]} nums
* @return {number}
*/
// 滑动窗口做法
// 时间复杂度:O(n),其中 nn 是数组的长度。指针start 和 end 最多各移动 n 次。
// 空间复杂度:O(1)
var minSubArrayLen = function(target, nums) {
let left = 0;
let total = 0;
let res = Infinity;
for(let right = 0; right < nums.length; right++) {
total += nums[right];
while(total >= target) {
res = Math.min(res, right - left + 1);
total -= nums[left++];
}
}
return res > nums.length ? 0 : res;
};
三、补充链接
https://leetcode-cn.com/problems/2VG8Kg/solution/shua-chuan-jian-zhi-offer-day06-shu-zu-i-d5ne/
四、补充部分
关注公众号:【深漂程序员小庄】:
内含丰富的学习资源和面试经验(不限前端、java),还有学习交流群可加,并且还有各大厂大佬可一起交流学习,一起进步~添加小庄微信,回复【加群】,可加入互联网技术交流群: