Merge pull request #24 from Please-to-study/master

添加0027.移除元素 与 0209.长度最小的子数组 JavaScript版本代码
This commit is contained in:
Carl Sun
2021-05-12 14:10:03 +08:00
committed by GitHub
2 changed files with 30 additions and 2 deletions

View File

@ -131,7 +131,20 @@ Python
Go Go
JavaScript:
```
//时间复杂度O(n)
//空间复杂度O(1)
var removeElement = (nums, val) => {
let k = 0;
for(let i = 0;i < nums.length;i++){
if(nums[i] != val){
nums[k++] = nums[i]
}
}
return k;
};
```
----------------------- -----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)

View File

@ -156,7 +156,22 @@ Python
Go 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) * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)