public static int partition(int[] nums, int start, int end) {
    int pivot = nums[start];
    while (start < end) {
      while (start < end && compare(pivot, nums[end])) end--;
      nums[start] = nums[end];
      while(start < end && compare(nums[start], pivot)) start++;
      nums[end] = nums[start];
    }
    nums[start] = pivot;
    return start;
  }