Two Sum - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

1
2
3
4
5
6
7
8
9
10
class Solution:
    def twoSum(self, nums: List[int], target: int-> List[int]:
        d = dict()
        for i, num in enumerate(nums):
            d[num] = i
            
        # and 찾은 index 가 자기 자신이 아니면
        for i, num in enumerate(nums):
            if target - num in d and d[target - num] != i :
                return [i, d[target - num]]
cs

 

'알고리즘 문제풀이 with 파이썬 > LeetCode' 카테고리의 다른 글

[배열] 3Sum  (0) 2021.09.09
[배열] Trapping Rain Water  (0) 2021.09.05
[문자열] Longest Palindromic Substring  (0) 2021.09.03
[문자열] Group Anagrams  (0) 2021.09.01
[문자열] Valid Palindrome  (0) 2021.08.30

+ Recent posts