-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
43 lines (29 loc) · 868 Bytes
/
Solution.java
File metadata and controls
43 lines (29 loc) · 868 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package leetcode.moveZeroes;
import java.util.Arrays;
public class Solution {
public void moveZeroes(int[] nums) {
int contadorNumeros = 0;
int n = nums.length;
for(int i = 0; i < n; i++){
int number = nums[i ];
if(number != 0){
nums[contadorNumeros] = number;
contadorNumeros++;
}
}
for(int i = contadorNumeros; i < nums.length; i++){
nums[i] = 0;
}
}
public static void main(String[] args) {
Solution s = new Solution();
int[] nums1 = {0,1,0,3,12};
int[] resultExpected = {1,3,12,0,0};
s.moveZeroes(nums1);
if(Arrays.equals(nums1, resultExpected)){
System.out.println("Correct");
} else {
System.out.println("Incorrect");
}
}
}