Two-Pointers Solution || Java || O(N^3) time
\nclass Solution {\n    public List<List<Integer>> fourSum(int[] nums, int target) {\n        List<List<Integer>>ans = new ArrayList<>();\n        Arrays.sort(n
```\nclass Solution {\n    public List<List<Integer>> fourSum(int[] nums, int target) {\n        List<List<Integer>>ans = new ArrayList<>();\n        Arrays.sort(nums);\n        for(int i=0; i<nums.length-3; i++) {\n            if(i==0 || i>0 && nums[i]!=nums[i-1]) {\n                for(int j=i+1; j<nums.length-2; j++) {\n                    if(j==i+1 || (j>i+1 && nums[j]!=nums[j-1])) {\n                        int low = j+1;\n                        int high = nums.length-1;\n\t\t\t\t\t\t\n\t\t\t\t\t\t//to prevent integer overflow\n                        long sum = nums[i]+nums[j];\n                        long val = ((long)target - sum);\n\t\t\t\t\t\t\n                        while(low < high) {\n                            if(nums[low]+nums[high] < val)\n                                low++;\n                            else if(nums[low]+nums[high] > val)\n                                high--;\n                            else {\n                                ans.add(Arrays.asList(nums[i], nums[j], nums[low], nums[high]));\n                                while(low<high && nums[low]==nums[low+1])\n                                    low++;\n                                while(low<high && nums[high]==nums[high-1])\n                                    high--;\n                                low++;\n                                high--;\n                            }\n                        }\n                    }\n                }\n            }\n        }\n        return ans;\n    }\n}\n```
['Two Pointers', 'Java']