classSolution(object): deffourSum(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[List[int]] """ if nums isNone: return [] length = len(nums) solns = set() if length < 4: return [] nums.sort() twoSums = {} for i in range(length): for j in range(i + 1, length): twoSum = nums[i] + nums[j] if twoSum in twoSums: twoSums[twoSum].append([i, j]) else: twoSums[twoSum] = [[i, j]] for k in range(length): for l in range(k + 1, length): diff = target - nums[k] - nums[l] if diff in twoSums: for ij in twoSums[diff]: if ij[0] > l: solns.add(tuple([nums[k], nums[l]] + [nums[ij[0]], nums[ij[1]]])) return [list(soln) for soln in solns]