Skip to content

add another js solution to leetcode problem: No.283 #361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions solution/0200-0299/0283.Move Zeroes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,26 @@ class Solution {
}
```

### **JavaScript**

```JavaScript
/**
* @param {number[]} nums
* @return {void} Do not return anything, modify nums in-place instead.
*/
var moveZeroes = function (nums) {
if (!nums.length) return nums;
let j = 0;
for (i = 0; i < nums.length; i++) {
if (nums[i]) {
if (i > j) [nums[i], nums[j]] = [nums[j], nums[i]];
j++;
}
}
return nums;
};
```

### **...**

```
Expand Down
19 changes: 19 additions & 0 deletions solution/0200-0299/0283.Move Zeroes/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,25 @@ class Solution {
}
}
```
### **JavaScript**

```JavaScript
/**
* @param {number[]} nums
* @return {void} Do not return anything, modify nums in-place instead.
*/
var moveZeroes = function (nums) {
if (!nums.length) return nums;
let j = 0;
for (i = 0; i < nums.length; i++) {
if (nums[i]) {
if (i > j) [nums[i], nums[j]] = [nums[j], nums[i]];
j++;
}
}
return nums;
};
```

### **...**

Expand Down
15 changes: 15 additions & 0 deletions solution/0200-0299/0283.Move Zeroes/Solution2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @param {number[]} nums
* @return {void} Do not return anything, modify nums in-place instead.
*/
var moveZeroes = function (nums) {
if (!nums.length) return nums;
let j = 0;
for (i = 0; i < nums.length; i++) {
if (nums[i]) {
if (i > j) [nums[i], nums[j]] = [nums[j], nums[i]];
j++;
}
}
return nums;
};