public ArrayList<ArrayList<Integer>> twoSum(int[] nums, int target) {
        ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();
        int left = 0, right = nums.length - 1;
        while (left < right) {
            int sum = nums[left] + nums[right];
            if (sum == target) {
                ArrayList<Integer> temp = new ArrayList<Integer>();
                temp.add(nums[left]);
                temp.add(nums[right]);
                result.add(temp);
                while (left < nums.length - 1 && nums[left] == nums[left + 1])
                    left++;
                while (right > 0 && nums[right] == nums[right - 1])
                    --right;
                left++;
                right--;
            } else if (sum < target)
                left++;
            else
                --right;
        }
        return result;
    }