Skip to content

Commit 84c6eef

Browse files
committed
add: two-sum problem solved
1 parent 77e3381 commit 84c6eef

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

two-sum/JiHyeonSu.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# 해시맵을 활용한 두 수의 합 구현
2+
# 시간복잡도 및 공간복잡도 O(n)
3+
class Solution:
4+
def twoSum(self, nums: List[int], target: int) -> List[int]:
5+
n_map = {}
6+
7+
for i, num in enumerate(nums):
8+
diff = target - num
9+
if diff in n_map:
10+
return [n_map[diff], i]
11+
n_map[num] = i

0 commit comments

Comments
 (0)