Skip to content

Commit 5f57c7b

Browse files
committed
Add Solution.java for 0283.Move Zeroes
1 parent bc4ec5d commit 5f57c7b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public void moveZeroes(int[] nums) {
3+
if (nums == null || nums.length <= 1) {
4+
return;
5+
}
6+
int count = 0, length = nums.length - 1;
7+
for (int i = 0; i <= length; i++) {
8+
if (nums[i] == 0) {
9+
count++;
10+
} else {
11+
nums[i - count] = nums[i];
12+
}
13+
}
14+
while (count-- > 0) {
15+
nums[length - count] = 0;
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)