class Solution:
def threeSum(self, nums: List[int]) -> List[List[int]]:
sums, seen = set(), set()
for i, num in enumerate(nums):
if i == 0 or nums != nums[i-1]:
seen = set()
for num2 in nums[i+1:]:
num3 = -(num+num2)
if num3 in seen:
sums.add(tuple(sorted([num, num2, num3])))
seen.add(num2)
return
import cProfile
from typing import List
import random
nums = [random.randint(-10000, 10000) for i in range(10000)]
def threeSum() -> List[List[int]]:
sums, dup, seen = set(), set(), set()
for i, num in enumerate(nums):
if num not in dup:
dup.add(num)
seen = set()
for num2 in nums[i+1:]:
num3 = -(num+num2)
if num3 in seen:
sums.add(tuple(sorted([num, num2, num3])))
seen.add(num2)
return sums
cProfile.run("threeSum()")