Last active
January 14, 2020 19:29
-
-
Save cashlo/74002d194969e46fbe310d9bcfe86e87 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
class Solution: | |
def threeSum(self, nums: List[int]) -> List[List[int]]: | |
nums_count_map = defaultdict(int) | |
result_set = set() | |
for n in nums: | |
nums_count_map[n] += 1 | |
for n in nums_count_map: | |
for m in nums_count_map: | |
if n == m and nums_count_map[n] < 2: | |
continue | |
target = 0 - m - n | |
if target in nums_count_map: | |
if target == n == m and nums_count_map[target] < 3: | |
continue | |
if (target == n or target == m) and nums_count_map[target] < 2: | |
continue | |
result_set.add( tuple(sorted([target, n, m])) ) | |
return result_set |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment