Skip to content

Commit 7d436fc

Browse files
author
sejineer
committed
two-sum solution
1 parent 31ea7ad commit 7d436fc

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

two-sum/sejineer.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""
2+
시간 복잡도 O(n)
3+
공간 복잡도 O(n)
4+
"""
5+
class Solution:
6+
def twoSum(self, nums: List[int], target: int) -> List[int]:
7+
nums_map = {}
8+
9+
for i, v in enumerate(nums):
10+
x = target - v
11+
if x in nums_map:
12+
j = nums_map[x]
13+
return [j, i]
14+
nums_map[v] = i

0 commit comments

Comments
 (0)