18. 4Sum
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nimport java.util.*;\n\nclass Solution {\n    public List<List<Integer>> fourSum(int[] nums, int target) {\n        List<List<Integer>> result = new ArrayList<>();\n        Set<List<Integer>> resultSet = new HashSet<>(); \n        \n        Arrays.sort(nums); \n        \n        for (int i = 0; i < nums.length - 3; i++) {\n            for (int j = i + 1; j < nums.length - 2; j++) {\n                int left = j + 1;\n                int right = nums.length - 1;\n                \n                while (left < right) {\n                    long sum = (long)nums[i] + nums[j] + nums[left] + nums[right];\n                    if (sum == target) {\n                        List<Integer> arr = new ArrayList<>();\n                        arr.add(nums[i]);\n                        arr.add(nums[j]);\n                        arr.add(nums[left]);\n                        arr.add(nums[right]);\n                        \n                        if (!resultSet.contains(arr)) {\n                            resultSet.add(arr); \n                        }\n                        \n                        left++;\n                        right--;\n                    } else if (sum <= target) {\n                        left++;\n                    } else if(sum > target){\n                        right--;\n                    }\n                }\n            }\n        }\n        \n        result.addAll(resultSet); \n        \n        return result;\n    }\n}\n```
['Java']