Guys , you can also solve problem number 2 by second approach. public static String shift(int[] arr) { int i = 0, m = 0; while (m < arr.length) { if (arr[m] == 0) { int val = arr[i]; arr[i] = arr[m]; arr[m] = val; i++; } m++; } return Arrays.toString(arr); } you should have to try once.
Guys , you can also solve problem number 2 by second approach.
public static String shift(int[] arr) {
int i = 0, m = 0;
while (m < arr.length) {
if (arr[m] == 0) {
int val = arr[i];
arr[i] = arr[m];
arr[m] = val;
i++;
}
m++;
}
return Arrays.toString(arr);
}
you should have to try once.