Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2e826d0

Browse files
authored
Merge pull requestneetcode-gh#1596 from aadil42/patch-37
2 parents17b4cc6 +5e3a2e4 commit2e826d0

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

‎javascript/283-Move-Zeroes.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
/**
2+
* Two Pointer
3+
* Time O(N) | Space O(N)
4+
* https://leetcode.com/problems/move-zeroes/
5+
*@param {number[]} nums
6+
*@return {void} Do not return anything, modify nums in-place instead.
7+
*/
8+
varmoveZeroes=function(nums){
9+
10+
constarr=newArray(nums.length).fill(0);
11+
12+
let[left,right]=[0,0];
13+
14+
while(right<nums.length){
15+
constisZero=(nums[right]===0);
16+
if(!isZero){
17+
arr[left]=nums[right];
18+
left++;
19+
}
20+
21+
right++;
22+
}
23+
24+
returnarr;
25+
};
26+
127
/**
228
* 2 Pointer
329
* Time O(N) | Space O(1)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp