4Sum LeetCode solution in Python
1class Solution:2def fourSum(self, nums: List[int], target: int) -> List[List[int]]:34if len(nums) < 4:5return []67nums.sort()8res = []910for i in range(len(nums)):11for j in range(i + 1, len(nums)):12l = j + 113r = len(nums) - 114while l < r:1516sum_ = nums[i] + nums[j] + nums[l] + nums[r]17a = [nums[i], nums[j], nums[l], nums[r]]1819if sum_ == target and a not in res:20res.append(a)2122if sum_ > target:23r -= 12425else:26l += 127while l < r and nums[l - 1] == nums[l]:28l += 12930return res3132# An Upvote will be encouraging