Skip to content

Commit 63a1ce5

Browse files
committed
Add solution #283
1 parent 150d179 commit 63a1ce5

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

solutions/0283-move-zeroes.js

+3-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
* https://leetcode.com/problems/move-zeroes/
44
* Difficulty: Easy
55
*
6-
* Given an integer array `nums`, move all `0`'s to the end of it while maintaining the relative order of the non-zero elements.
6+
* Given an integer array nums, move all 0's to the end of it while maintaining the
7+
* relative order of the non-zero elements.
78
*
89
* Note that you must do this in-place without making a copy of the array.
910
*/
@@ -15,15 +16,7 @@
1516
var moveZeroes = function(nums) {
1617
for (let i = 0, j = 0; i < nums.length; i++) {
1718
if (nums[i] !== 0) {
18-
swap(nums, i, j++);
19+
[nums[i], nums[j++]] = [nums[j], nums[i]];
1920
}
2021
}
21-
22-
return nums;
2322
};
24-
25-
function swap(nums, i, j) {
26-
const temp = nums[i];
27-
nums[i] = nums[j];
28-
nums[j] = temp;
29-
}

0 commit comments

Comments
 (0)