*Java* a little bit faster than other common methods (9ms, beats 95%)
To avoid duplicate list items, I skip unnecessary indices at two locations:\n\n - one at the end of the outer loop (i-loop)\n - the other at the end of the inne
To avoid duplicate list items, I skip unnecessary indices at two locations:\n\n - one at the end of the outer loop (`i-loop`)\n - the other at the end of the inner loop (`j-loop`). \n\n\nTo avoid useless computations, the following is kind of critical:\n\n - the function `return` immediately when `nums[i]*4 > target`\n - the inner loop `break` immediately when `nums[j]*4 < target`. \n\nThese two lines save quite some time due to the set up of the test cases in OJ.\n\n    public class Solution {\n        public List<List<Integer>> fourSum(int[] nums, int target) {\n            List<List<Integer>> list = new ArrayList<List<Integer>>();\n            Arrays.sort(nums);\n            int second = 0, third = 0, nexti = 0, nextj = 0;\n            for(int i=0, L=nums.length; i<L-3; i++) {\n                if(nums[i]<<2 > target) return list; // return immediately\n                for(int j=L-1; j>i+2; j--) {\n                    if(nums[j]<<2 < target) break; // break immediately\n                    int rem = target-nums[i]-nums[j];\n                    int lo = i+1, hi=j-1;\n                    while(lo<hi) {\n                        int sum = nums[lo] + nums[hi];\n                        if(sum>rem) --hi;\n                        else if(sum<rem) ++lo;\n                        else {\n                            list.add(Arrays.asList(nums[i],nums[lo],nums[hi],nums[j]));\n                            while(++lo<=hi && nums[lo-1]==nums[lo]) continue; // avoid duplicate results\n                            while(--hi>=lo && nums[hi]==nums[hi+1]) continue; // avoid duplicate results\n                        }\n                    }\n                    while(j>=1 && nums[j]==nums[j-1]) --j; // skip inner loop\n                }\n                while(i<L-1 && nums[i]==nums[i+1]) ++i; // skip outer loop\n            }\n            return list;\n        }\n    }
['Java']