We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0794f6b commit 1614c33Copy full SHA for 1614c33
javascript/283-Move-Zeroes.js
@@ -1,24 +1,20 @@
1
/**
2
* Linear Time
3
* Time Complexity O(N) | Space Complexity 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
var moveZeroes = function(nums) {
9
10
const zeroAtTheEnd = Array(nums.length).fill(0);
11
let left = 0;
- let right = zeroAtTheEnd.length - 1;
12
-
13
for (let i = 0; i < nums.length; i++) {
14
- if (nums[i] === 0) {
15
- right--;
16
- } else {
+ if (nums[i]) {
17
zeroAtTheEnd[left] = nums[i];
18
left++;
19
}
20
21
22
return zeroAtTheEnd;
23
};
24
0 commit comments