""" Time: O(N^3) Space: O(1) Using tuple to remove redundant, each `ans.add(tuple(sorted([nums[a], nums[b], nums[c], nums[d]])))` is using constant time and space. So no increase to the time and space complexity. """ class Solution(object): def fourSum(self, nums, target): nums.sort() N = len(nums) ans = set() for a in xrange(N): for b in xrange(a+1, N): c = b+1 d = N-1 while ctarget: d -= 1 elif s0 and nums[a]==nums[a-1]: continue for b in xrange(a+1, N): if b>0 and nums[b]==nums[b-1] and a!=b-1: continue c = b+1 d = N-1 while ctarget: d -= 1 elif s