Skip to content

Commit 1eb1375

Browse files
solves move zeros
1 parent ea92036 commit 1eb1375

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/MoveZeros.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public class MoveZeros {
2+
public static void moveZeroes(int[] array) {
3+
int[] result = new int[array.length];
4+
for (int index = 0, j = 0 ; index < array.length ; index++) {
5+
if (array[index] != 0) {
6+
result[j++] = array[index];
7+
}
8+
}
9+
10+
for (int index = 0 ; index < array.length ; index++) {
11+
array[index] = result[index];
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)