Skip to content

Commit abfd7d9

Browse files
author
김가은
committed
two-sum solution
1 parent cc9a53d commit abfd7d9

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

two-sum/paran22.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution:
2+
# 시간복잡도 : O(n)
3+
def twoSum(self, nums: List[int], target: int) -> List[int]:
4+
num_dict = {num: i for i, num in enumerate(nums)}
5+
6+
for i, first_num in enumerate(nums):
7+
second_num = target - first_num
8+
if second_num in num_dict and num_dict[second_num] != i:
9+
return [i, num_dict[second_num]]

0 commit comments

Comments
 (0)