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 59b9d59 commit d6c4d91Copy full SHA for d6c4d91
LeetCode/283. Move Zeroes/index.js
@@ -0,0 +1,20 @@
1
+var moveZeroes = function(nums) {
2
+ if (nums.length === 1) return nums;
3
+
4
+ let count = 0;
5
+ for (let i = 0; i < nums.length; i++) {
6
+ if (nums[i] === 0) {
7
+ count++;
8
+ nums.splice(i, 1);
9
+ i--;
10
+ }
11
12
13
+ for (let i = 1; i <= count; i++) {
14
+ nums.push(0);
15
16
17
+ return nums;
18
+};
19
20
+console.log(moveZeroes([0, 0, 1]));
0 commit comments