From 74ba60e18a0a5951f0b96011c12095a97387b685 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9C=B2=E4=BB=8E=E4=BB=8A=E5=A4=9C=E7=99=BD?= <1101131319@qq.com> Date: Wed, 12 May 2021 13:15:11 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A00027.=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E5=85=83=E7=B4=A0.md=20JavaScript=E7=89=88=E6=9C=AC=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0027.移除元素.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/problems/0027.移除元素.md b/problems/0027.移除元素.md index 3772d754..5cfdb68d 100644 --- a/problems/0027.移除元素.md +++ b/problems/0027.移除元素.md @@ -131,7 +131,20 @@ Python: 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) From 24ba15df6d09bb8a4ae5c5dabc2fe399f883a228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9C=B2=E4=BB=8E=E4=BB=8A=E5=A4=9C=E7=99=BD?= <1101131319@qq.com> Date: Wed, 12 May 2021 13:18:00 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A00209.=E9=95=BF=E5=BA=A6?= =?UTF-8?q?=E6=9C=80=E5=B0=8F=E7=9A=84=E5=AD=90=E6=95=B0=E7=BB=84=20JavaSc?= =?UTF-8?q?ript=E7=89=88=E6=9C=AC=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0209.长度最小的子数组.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/problems/0209.长度最小的子数组.md b/problems/0209.长度最小的子数组.md index c3937d7b..1b00c4e3 100644 --- a/problems/0209.长度最小的子数组.md +++ b/problems/0209.长度最小的子数组.md @@ -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)