We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 150d179 commit 63a1ce5Copy full SHA for 63a1ce5
solutions/0283-move-zeroes.js
@@ -3,7 +3,8 @@
3
* https://leetcode.com/problems/move-zeroes/
4
* Difficulty: Easy
5
*
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.
+ * 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.
8
9
* Note that you must do this in-place without making a copy of the array.
10
*/
@@ -15,15 +16,7 @@
15
16
var moveZeroes = function(nums) {
17
for (let i = 0, j = 0; i < nums.length; i++) {
18
if (nums[i] !== 0) {
- swap(nums, i, j++);
19
+ [nums[i], nums[j++]] = [nums[j], nums[i]];
20
}
21
-
22
- return nums;
23
};
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