https://leetcode.com/problems/two-sum/
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
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
res = []
dicts = {}
for i in range(len(nums)):
if (target - nums[i]) in dicts:
value = dicts[target - nums[i]]
res.append(value)
res.append(i)
else:
dicts[nums[i]] = i
return res
'알고리즘 > Leetcode' 카테고리의 다른 글
[leetcode/python3] 485. Max Consecutive Ones (0) | 2021.09.22 |
---|---|
[leetcode/python3] 565. Array Nesting (0) | 2021.09.18 |
[leetcode/python3] 1768.Merge Strings Alternately (0) | 2021.04.10 |
[leetcode/kotlin] 575.Distribute Candies (0) | 2021.03.16 |
[leetcode/kotlin] 104. Maximum Depth of Binary Tree (0) | 2020.12.05 |