(Java) 25 lines of code, easy to understand answer that is O(n^2), based on two sum solution
\n    public List<List<Integer>> fourSum(int[] nums, int target) {\n        //because res can be duplicated, we use set to deal with that\n        //Set of a li
```\n    public List<List<Integer>> fourSum(int[] nums, int target) {\n        //because res can be duplicated, we use set to deal with that\n        //Set of a list compare all the elements in the list defaultly, you don\'t need to override compare and hash function\n        Set<List<Integer>> res = new HashSet<List<Integer>>();\n        if(nums == null || nums.length < 4) {\n            return new ArrayList<>(res);\n        }\n        int n = nums.length;\n        Arrays.sort(nums);\n        //key represents sum of first two nums, value is the list of indexes of those two nums\n        //We dont need to worry about duplicate here, we deal with that in res set\n        Map<Integer, List<int[]>> map = new HashMap<>();\n        for(int i = 0; i < n; i++) {\n            for(int j = i + 1; j < n; j++) {\n                int sum = nums[i] + nums[j];\n                //check if current nums[i] and nums[j] can combine with previous first two nums to get a target value; \n\t\t\t\tif(map.containsKey(target - sum)) {\n                    List<int[]> indexes = map.get(target - sum);\n\t\t\t\t\tfor(int[] index : indexes) {\n                        // Here we already know that we can get 4 nums to get the target value, but we need those four nums comes in order\n\t\t\t\t\t\t//assume we have first two nums nums[k], nums[l], and current nums are nums[i], nums[j], by definition, k < l and i < j are certain. So we only need to make sure that  l < i, then we can get k < l < i < j, and add it to result set \n\t\t\t\t\t\tif(index[1] < i) {\n                            //make a result\n                            List<Integer> candidate = Arrays.asList(nums[index[0]], nums[index[1]], nums[i], nums[j]);\n                            res.add(candidate);\n                        }\n                    }\n                }\n                List<int[]> temp = map.getOrDefault(sum, new ArrayList<>());\n                temp.add(new int[]{i, j});\n                map.put(sum, temp);\n            }\n        }\n        //convert from Set<List> to List<List>\n        return new ArrayList<>(res);\n    }\n```
[]