Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.37 KB | None | 0 0
  1. class Solution {
  2.     public int[] sortArrayByParity(int[] A) {
  3.         int i = 0;
  4.         int j = A.length - 1;
  5.         int[] result = new int[A.length];
  6.        
  7.         for(int x : A) {
  8.             if (x % 2 == 0) {
  9.                 result[i++] = x;
  10.             } else {
  11.                 result[j--] = x;
  12.             }
  13.         }
  14.         return result;
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement