forked from lgaBug/algorithm014-algorithm014
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.java
More file actions
29 lines (26 loc) · 666 Bytes
/
Copy pathmain.java
File metadata and controls
29 lines (26 loc) · 666 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
27
28
29
package Week_01.Move_zeros_283;
import java.util.Arrays;
public class main {
public static void main(String[] args) {
int[] nums = new int[]{0,1,2,0,3,0,4};
Solution s = new Solution();
s.moveZeroes(nums);
System.out.println(Arrays.toString(nums));
}
}
class Solution {
public void moveZeroes(int[] nums) {
if (nums == null) {
return;
}
int j = 0;
for ( int i = 0; i < nums.length; i++) {
if ( nums[i] != 0) {
int tmp = nums[j];
nums[j] = nums[i];
nums[i] = tmp;
j++;
}
}
}
}