Skip to content

Commit abce85a

Browse files
author
jinbeom
committed
Two Sum Solution
1 parent 713cfed commit abce85a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

two-sum/kayden.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# 시간복잡도: O(N)
2+
# 공간복잡도: O(N)
3+
class Solution:
4+
def twoSum(self, nums: List[int], target: int) -> List[int]:
5+
check = {}
6+
7+
for idx, num in enumerate(nums):
8+
check[num] = idx
9+
10+
for idx, num in enumerate(nums):
11+
if num * 2 == target:
12+
if check[num] != idx:
13+
return [idx, check[num]]
14+
else:
15+
continue
16+
17+
if target - num in check:
18+
return [check[num], check[target - num]]
19+
20+
return []

0 commit comments

Comments
 (0)