public List<List<Integer>> threeSum(int[] nums) {
        List<List<Integer>> result = new ArrayList<List<Integer>>();
        Arrays.sort(nums);
        for (int i = 0; i < nums.length - 2; ++i) {
            int val = nums[i];
            for (ArrayList<Integer> arr : twoSum(
                    Arrays.copyOfRange(nums, i + 1, nums.length), -nums[i])) {
                ArrayList<Integer> temp = new ArrayList<Integer>();
                temp.add(val);
                temp.addAll(arr);
                result.add(temp);
            }
            while (i < nums.length - 1 && nums[i] == nums[i + 1])
                i++;
        }
        return result;
    }