We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents e475213 + d6e59eb commit 7943619Copy full SHA for 7943619
javascript/283-Move-Zeroes.js
@@ -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