Skip to content

Commit 156c921

Browse files
authored
Update 0283-move-zeroes.cs
Solution with more like NeetCode Way
1 parent fb3a444 commit 156c921

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

csharp/0283-move-zeroes.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,20 @@ public void MoveZeroes(int[] nums)
2121
readIndex++;
2222
}
2323
}
24-
}
24+
}
25+
26+
public class NeetCodeWaySolution { //NeetCodeWay
27+
public void MoveZeroes(int[] nums) {
28+
if (nums.Length <= 1) return;
29+
int l = 0, r = 0;
30+
while (r < nums.Length) {
31+
if (nums[r] != 0) {
32+
var t = nums[l];
33+
nums[l++] = nums[r];
34+
nums[r++] = t;
35+
} else {
36+
++r;
37+
}
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)