Skip to content

Commit 4023034

Browse files
authored
Merge pull request #2270 from gourgopal/patch-8
Update 0283-move-zeroes.cs
2 parents 22814eb + 156c921 commit 4023034

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

Diff for: csharp/0283-move-zeroes.cs

+17-1
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)