package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/sort-array-by-parity/
 */
public class Problem905 {
    public int[] sortArrayByParity(int[] A) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem905 prob = new Problem905();
        System.out.println(Arrays.toString(prob.sortArrayByParity(new int[]{3, 1, 2, 4}))); // [2,4,3,1]
    }
}

package leetcode;

/**
 * https://leetcode.com/problems/sort-array-by-parity/
 */
public class Problem905 {
    public int[] sortArrayByParity(int[] A) {
        int[] result = new int[A.length];
        int idx = 0;
        for (int i = 0; i < A.length; i++) {
            if (A[i] % 2 == 0) {
                result[idx++] = A[i];
            }
        }
        for (int i = 0; i < A.length; i++) {
            if (A[i] % 2 != 0) {
                result[idx++] = A[i];
            }
        }
        return result;
    }
}

Solve problem 905