function minSubArrayLen(target: number, nums: number[]): number {
const n = nums.length
//利用双指针
//1.对数组中的值进行求和操作
//2.当sum >= target时,进行sum-=nums[left++]操作,left往前进行最小长度保存
//3.接着进行循环判断,最后会找到最小长度
let left:number = 0;
let right:number = 0;
let sum:number = 0;
let min = Number.MAX_VALUE;
while(right < n ) {
//累加操作
sum +=nums[right++]
//当sum>=target时进行长度缩减操作
while(sum >= target ) {
min = Math.min(min, right - left)
sum-=nums[left++]
}
}
return min === Number.MAX_VALUE ? 0 : min
};