Golang concise 26ms solution
Just pick the first element and then for the remaining array, apply 3 sum.\nO(n^3) .\n\n\nfunc fourSum(nums []int, target int) [][]int {\n\tsort.Ints(nums)\n\tv
Just pick the first element and then for the remaining array, apply 3 sum.\n`O(n^3)` .\n\n```\nfunc fourSum(nums []int, target int) [][]int {\n\tsort.Ints(nums)\n\tvar res [][]int\n\tfor i := 0; i < len(nums)-3; i++ {\n\t\tif i != 0 && nums[i] == nums[i-1] {\n\t\t\tcontinue\n\t\t}\n\t\tthreeSum(&res, nums[i], nums[i+1:], target-nums[i])\n\t}\n\treturn res\n}\n\nfunc threeSum(res *[][]int, first int, nums []int, target int) {\n\tnlen := len(nums)\n\tfor i := 0; i < nlen-2; i++ {\n\t\tif i != 0 && nums[i] == nums[i-1] {\n\t\t\tcontinue\n\t\t}\n\n\t\tleft, right := i+1, nlen-1\n\t\tfor left < right {\n\t\t\tsum := nums[i] + nums[left] + nums[right]\n\t\t\tif sum == target {\n\t\t\t\t*res = append(*res, []int{first, nums[i], nums[left], nums[right]})\n\t\t\t\tfor left < right && nums[left] == nums[left+1] {\n\t\t\t\t\tleft++\n\t\t\t\t}\n\t\t\t\tfor left < right && nums[right] == nums[right-1] {\n\t\t\t\t\tright--\n\t\t\t\t}\n\t\t\t\tleft++\n\t\t\t\tright--\n\t\t\t} else if sum < target {\n\t\t\t\tfor left < right && nums[left] == nums[left+1] {\n\t\t\t\t\tleft++\n\t\t\t\t}\n\t\t\t\tleft++\n\t\t\t} else {\n\t\t\t\tfor left < right && nums[right] == nums[right-1] {\n\t\t\t\t\tright--\n\t\t\t\t}\n\t\t\t\tright--\n\t\t\t}\n\t\t}\n\t}\n}\n```
['Go']