- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem286.java
More file actions
Latest commit
26 lines (24 loc) · 556 Bytes
/
Copy pathProblem286.java
File metadata and controls
26 lines (24 loc) · 556 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
classProblem286 {
publicstaticvoidmain(String[] args) {
int[] nums = newint[]{};
newProblem286().moveZeroes(nums);
for (inti = 0; i < nums.length; i++) {
System.out.print(nums[i] + ",");
}
}
publicvoidmoveZeroes(int[] nums) {
intj = 0;
for (inti = 0; i < nums.length && j < nums.length;) {
if (nums[i] != 0) {
nums[j] = nums[i];
i++;
j++;
} else {
i++;
}
}
for (intk = j; k < nums.length; k++) {
nums[k] = 0;
}
}
}