mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
添加0027.移除元素.md JavaScript版本。
This commit is contained in:
@ -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)
|
||||||
|
Reference in New Issue
Block a user