Sort Array By Parity
Description
Code
public int[] sortArrayByParity(int[] A) {
int i = 0;
int j = A.length - 1;
int t = 0;
while (i < j) {
while (A[i] % 2 != 1 && i < j) {
i++;
}
while (A[j] % 2 != 0 && i < j) {
j--;
}
t = A[i];
A[i] = A[j];
A[j] = t;
i++;
j--;
}
return A;
}Last updated