public int helper(int[] nums, int begin, int end) {
        int pivot = nums[begin];
        int l = begin + 1, r = end;
        while (l <= r) {
            if (nums[l] > pivot && nums[r] < pivot)
                swap(nums, l++, r--);
            if (nums[l] <= pivot)
                ++l;
            if (nums[r] >= pivot)
                --r;
        }
        swap(nums, begin, r);
        return r;
    }