//Given [1, 2, 3, 4], return [1, 3, 2, 4]
 public void partitionArray(int[] nums) {
        // write your code here;
       int start = 0;
       int end = nums.length - 1;
       if (start > end) return;
       while (start < end) {
           while (nums[start] % 2 != 0) {
               start++;
           }
           while (nums[end] % 2 == 0) {
               end--;
           }
           if (start < end) {
               int tmp = nums[start];
               nums[start] = nums[end];
               nums[end] = tmp;
               start++;
               end--;
           }
       }
    }

results matching ""

    No results matching ""