Given a n array of N integers nums, judge whether there are three elements a, b, c in nums, so that a + b + c = 0? Find all triples that meet the conditions and are not repeated.

Note: the answer cannot contain duplicate triples.

For example, given the array nums = [-1, 0, 1, 2, -1, -4],

The required set of triples is:
[
  [-1, 0, 1],
  [-1, -1, 2]
]

Source: LeetCode
 Link: https://leetcode-cn.com/problems/3sum
 Copyright belongs to the network. For commercial reprint, please contact the official authorization. For non-commercial reprint, please indicate the source.

1. Never run more than 0000... 0000... , I'm so angry that I use a sneaker if, but sometimes I can't run. I guess it's related to the network speed. This N zeros can't all be added to the comparison queue, and the earlier I get rid of them, the faster I can run.

class Solution {
    public List<List<Integer>> threeSum(int[] nums) {
        /*
        set<List>Duplicate removal
        */
        List<List<Integer>> ans = new ArrayList<>();
        if(nums.length<3)
            return ans;
        Set<List<Integer>> ret = new HashSet<>();
        Map<Integer,Integer> map = new HashMap<>();
        //The original intention is to sort and then traverse the pruning backward to find the map actually forward
        Arrays.sort(nums);
        boolean flag = false;
        for(int i=1 ; i<nums.length ; i++){
            map.put(nums[i-1],i-1);
            for(int j=i+1 ; j<nums.length ; j++){
                //Stealing chicken has passed N 0, ha ha
                if( nums[i]==0 && nums[j]==0 && map.containsKey(0) ){
                    flag = true;
                    continue;
                }
                    
                if(map.containsKey(-(nums[i]+nums[j]))){
                    List<Integer> tmp = new ArrayList<>();
                    tmp.add(nums[i]);
                    tmp.add(nums[j]);
                    tmp.add(-(nums[i]+nums[j]));
                    if(!ret.contains(tmp)){
                        ret.add(tmp);
                        ans.add(tmp);
                    }
                }
            }
        }
        if(flag){
            ans.add(new ArrayList<Integer>(Arrays.asList(0,0,0)));
        }
        return ans;
    }
}

2. Here, the left and right settings are unreasonable. They are repeated from beginning to end every time, and they have to be de duplicated with set. The left and right after mid should be set to left and right.
True vegetable

class Solution {
    public List<List<Integer>> threeSum(int[] nums) {
        List<List<Integer>> ans = new ArrayList<>();
        if(nums.length<3)
            return ans;
        Arrays.sort(nums);
        Set<List<Integer>> set = new HashSet<>();
        
        for(int mid=1 ; mid<nums.length ; mid++){
            int left=0, right=nums.length-1;
            // 000... 0000... Or 1111.... 111...
            while(left<mid && mid<right){
                if(nums[left] == nums[right]){
                    if(nums[left] == 0){
                        if(!set.contains(Arrays.asList(0,0,0)))
                        ans.add(Arrays.asList(nums[left],nums[left],nums[left]));
                        set.add(Arrays.asList(nums[left],nums[left],nums[left]));
                    }
                    break;
                }
                int sum = nums[left]+nums[right]+nums[mid];
                if(  (right<nums.length-1 && nums[right] == nums[right+1]) || sum>0){
                    right--;
                }else if((left!=0 && nums[left] == nums[left-1]) || sum<0){
                    left++;
                }else{
                    if(!set.contains(Arrays.asList(nums[left],nums[mid],nums[right]))){
                        ans.add(Arrays.asList(nums[left],nums[mid],nums[right]));
                        set.add(Arrays.asList(nums[left],nums[mid],nums[right]));
                    }
                    left++;
                    right--;
                }
            }
        }
        return ans;
    }
}