res := make([][]int, 0) for i :=0; i<len(nums)-3; i++ { if i > 0 && nums[i-1] == nums[i] { continue } for j := i+1; j<len(nums)-2; j++ { if j>i+1 && nums[j] == nums[j-1] { continue }
k := j+1 r := len(nums)-1
for k < r { sum := nums[i]+nums[j]+nums[k]+nums[r] if sum < target { k++ }
if sum > target { r-- }
if sum == target { res = append(res, []int{nums[i],nums[j],nums[k],nums[r]}) k++ for k < r && nums[k]==nums[k-1] { k++ } r-- for k < r && nums[r]==nums[r+1] { r-- } } }