We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a936fe7 commit 116e233Copy full SHA for 116e233
3sum/HodaeSsi.py
@@ -0,0 +1,22 @@
1
+# 시간복잡도 O(n^2), 공간복잡도 O(n^2)
2
+class Solution:
3
+ def threeSum(self, nums: List[int]) -> List[List[int]]:
4
+ # key: 값, value: list((i, j))
5
+ dic = {}
6
+ answer = set()
7
+
8
+ # 이중 for문으로 모든 경우의 수를 구합니다.
9
+ for i in range(len(nums)):
10
+ for j in range(i+1, len(nums)):
11
+ if nums[i] + nums[j] in dic:
12
+ dic[nums[i] + nums[j]].append((i, j))
13
+ else:
14
+ dic[nums[i] + nums[j]] = [(i, j)]
15
16
+ for k in range(len(nums)):
17
+ for i, j in dic.get(-nums[k], []):
18
+ if i != k and j != k:
19
+ answer.add(tuple(sorted([nums[i], nums[j], nums[k]])))
20
21
+ return list(answer)
22
0 commit comments