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 592b870 commit e09d4b7Copy full SHA for e09d4b7
283. Move Zeroes.js
@@ -21,3 +21,24 @@ Constraints:
21
Follow up: Could you minimize the total number of operations done?
22
23
*/
24
+
25
+/**
26
+ * @param {number[]} nums
27
+ * @return {void} Do not return anything, modify nums in-place instead.
28
+ */
29
+const moveZeroes = (nums) => {
30
+ let index = 0;
31
32
+ for (const num of nums) {
33
+ if (num !== 0) {
34
+ nums[index] = num;
35
+ index++;
36
+ }
37
38
39
+ for (let i = index; i < nums.length; i++) {
40
+ nums[i] = 0;
41
42
43
+ return nums;
44
+};
0 commit comments