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.
2 parents 17b4cc6 + 5e3a2e4 commit 2e826d0Copy full SHA for 2e826d0
javascript/283-Move-Zeroes.js
@@ -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
+var moveZeroes = function(nums) {
9
+
10
+ const arr = new Array(nums.length).fill(0);
11
12
+ let [left, right] = [0, 0];
13
14
+ while (right < nums.length) {
15
+ const isZero = (nums[right] === 0);
16
+ if (!isZero) {
17
+ arr[left] = nums[right];
18
+ left++;
19
+ }
20
21
+ right++;
22
23
24
+ return arr;
25
+};
26
27
/**
28
* 2 Pointer
29
* Time O(N) | Space O(1)
0 commit comments