From 7ed1753f8f23bdf30822be005d30a3ea2059030e 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] =?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)