7ms java code win over 100%
The first time win over 100%. Basic idea is using subfunctions for 3sum and 2sum, and keeping throwing all impossible cases. O(n^3) time complexity, O(1) extra 
The first time win over 100%. Basic idea is using subfunctions for 3sum and 2sum, and keeping throwing all impossible cases. O(n^3) time complexity, O(1) extra space complexity.\n\n    public List<List<Integer>> fourSum(int[] nums, int target) {\n\t\t\tArrayList<List<Integer>> res = new ArrayList<List<Integer>>();\n\t\t\tint len = nums.length;\n\t\t\tif (nums == null || len < 4)\n\t\t\t\treturn res;\n\n\t\t\tArrays.sort(nums);\n\n\t\t\tint max = nums[len - 1];\n\t\t\tif (4 * nums[0] > target || 4 * max < target)\n\t\t\t\treturn res;\n\n\t\t\tint i, z;\n\t\t\tfor (i = 0; i < len; i++) {\n\t\t\t\tz = nums[i];\n\t\t\t\tif (i > 0 && z == nums[i - 1])// avoid duplicate\n\t\t\t\t\tcontinue;\n\t\t\t\tif (z + 3 * max < target) // z is too small\n\t\t\t\t\tcontinue;\n\t\t\t\tif (4 * z > target) // z is too large\n\t\t\t\t\tbreak;\n\t\t\t\tif (4 * z == target) { // z is the boundary\n\t\t\t\t\tif (i + 3 < len && nums[i + 3] == z)\n\t\t\t\t\t\tres.add(Arrays.asList(z, z, z, z));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tthreeSumForFourSum(nums, target - z, i + 1, len - 1, res, z);\n\t\t\t}\n\n\t\t\treturn res;\n\t\t}\n\n\t\t/*\n\t\t * Find all possible distinguished three numbers adding up to the target\n\t\t * in sorted array nums[] between indices low and high. If there are,\n\t\t * add all of them into the ArrayList fourSumList, using\n\t\t * fourSumList.add(Arrays.asList(z1, the three numbers))\n\t\t */\n\t\tpublic void threeSumForFourSum(int[] nums, int target, int low, int high, ArrayList<List<Integer>> fourSumList,\n\t\t\t\tint z1) {\n\t\t\tif (low + 1 >= high)\n\t\t\t\treturn;\n\n\t\t\tint max = nums[high];\n\t\t\tif (3 * nums[low] > target || 3 * max < target)\n\t\t\t\treturn;\n\n\t\t\tint i, z;\n\t\t\tfor (i = low; i < high - 1; i++) {\n\t\t\t\tz = nums[i];\n\t\t\t\tif (i > low && z == nums[i - 1]) // avoid duplicate\n\t\t\t\t\tcontinue;\n\t\t\t\tif (z + 2 * max < target) // z is too small\n\t\t\t\t\tcontinue;\n\n\t\t\t\tif (3 * z > target) // z is too large\n\t\t\t\t\tbreak;\n\n\t\t\t\tif (3 * z == target) { // z is the boundary\n\t\t\t\t\tif (i + 1 < high && nums[i + 2] == z)\n\t\t\t\t\t\tfourSumList.add(Arrays.asList(z1, z, z, z));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\ttwoSumForFourSum(nums, target - z, i + 1, high, fourSumList, z1, z);\n\t\t\t}\n\n\t\t}\n\n\t\t/*\n\t\t * Find all possible distinguished two numbers adding up to the target\n\t\t * in sorted array nums[] between indices low and high. If there are,\n\t\t * add all of them into the ArrayList fourSumList, using\n\t\t * fourSumList.add(Arrays.asList(z1, z2, the two numbers))\n\t\t */\n\t\tpublic void twoSumForFourSum(int[] nums, int target, int low, int high, ArrayList<List<Integer>> fourSumList,\n\t\t\t\tint z1, int z2) {\n\n\t\t\tif (low >= high)\n\t\t\t\treturn;\n\n\t\t\tif (2 * nums[low] > target || 2 * nums[high] < target)\n\t\t\t\treturn;\n\n\t\t\tint i = low, j = high, sum, x;\n\t\t\twhile (i < j) {\n\t\t\t\tsum = nums[i] + nums[j];\n\t\t\t\tif (sum == target) {\n\t\t\t\t\tfourSumList.add(Arrays.asList(z1, z2, nums[i], nums[j]));\n\n\t\t\t\t\tx = nums[i];\n\t\t\t\t\twhile (++i < j && x == nums[i]) // avoid duplicate\n\t\t\t\t\t\t;\n\t\t\t\t\tx = nums[j];\n\t\t\t\t\twhile (i < --j && x == nums[j]) // avoid duplicate\n\t\t\t\t\t\t;\n\t\t\t\t}\n\t\t\t\tif (sum < target)\n\t\t\t\t\ti++;\n\t\t\t\tif (sum > target)\n\t\t\t\t\tj--;\n\t\t\t}\n\t\t\treturn;\n\t\t}
['Java']