Skip to content

Commit e7a1b5e

Browse files
committed
two-sum solution
1 parent 8917da0 commit e7a1b5e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

two-sum/ohkingtaek.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
def twoSum(self, nums: List[int], target: int) -> List[int]:
3+
"""
4+
nums를 앞에서부터 하나씩 보면서 현재 값(nums[i])과 더해서 target이 되는 값이 뒤쪽 배열에 있는지 확인합니다.
5+
있으면 그 값의 index를 찾아서 같이 반환합니다.
6+
"""
7+
dp = []
8+
for i in range(len(nums)):
9+
if (target - nums[i]) in nums[i+1:]:
10+
return [i, nums[i+1:].index(target - nums[i]) + i+1]
11+

0 commit comments

Comments
 (0)