添加0209.长度最小的子数组 JavaScript版本。

This commit is contained in:
露从今夜白 2021-05-12 13:18:00 +08:00 committed by GitHub
parent 74ba60e18a
commit 24ba15df6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 1 deletions

View File

@ -156,7 +156,22 @@ Python
Go
JavaScript:
```
var minSubArrayLen = (target, nums) => {
let left = 0, right = 0,win = Infinity,sum = 0;
while(right < nums.length){
sum += nums[right];
while(sum >= target){
win = right - left + 1 < win? right - left + 1 : win;
sum -= nums[left];
left++;
}
right++;
}
return win === Infinity? 0:win;
};
```
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)