class Solution:
def fourSum(self, nums, target: int):
if len(nums) < 4:
return []
output = []
def backtrack(path, next):
if len(path) == 4:
output.append(sorted(path))
return
for index, element in enumerate(next):
path.append(element)
backtrack(path, next[index + 1:])
path.pop()
backtrack([], nums)
result = []
for element in output:
if sum(element) == target and element not in result:
result.append(element)
return result