Advertisement
ogv

Untitled

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