Skip to content

Commit 7943619

Browse files
authored
Merge pull request #1505 from FahadulShadhin/js-solutions
Adding 283-Move-Zeroes.js
2 parents e475213 + d6e59eb commit 7943619

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Diff for: javascript/283-Move-Zeroes.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* 2 Pointer
3+
* Time O(N) | Space O(1)
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+
var moveZeroes = (nums) => {
9+
let [ left, right ] = [ 0, 0 ];
10+
11+
while (right < nums.length) {
12+
const canSwap = (nums[right] !== 0)
13+
if (canSwap) {
14+
[nums[left], nums[right]] = [nums[right], nums[left]];
15+
left++;
16+
}
17+
18+
right++;
19+
}
20+
};

0 commit comments

Comments
 (0)