Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1614c33

Browse files
authored
Update 283-Move-Zeroes.js
Updated the logic. We don't need the "else" part nor do we require "continue".
1 parent0794f6b commit1614c33

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

‎javascript/283-Move-Zeroes.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
/**
22
* Linear Time
33
* Time Complexity O(N) | Space Complexity O(N);
4+
* https://leetcode.com/problems/move-zeroes/
45
*@param {number[]} nums
56
*@return {void} Do not return anything, modify nums in-place instead.
67
*/
78
varmoveZeroes=function(nums){
89

910
constzeroAtTheEnd=Array(nums.length).fill(0);
1011
letleft=0;
11-
letright=zeroAtTheEnd.length-1;
12-
1312
for(leti=0;i<nums.length;i++){
14-
if(nums[i]===0){
15-
right--;
16-
}else{
13+
if(nums[i]){
1714
zeroAtTheEnd[left]=nums[i];
1815
left++;
1916
}
2017
}
21-
2218
returnzeroAtTheEnd;
2319
};
2420

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp