Leetcode 1. Two Sum - Python Simple Solution

preview_player
Показать описание
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.

You can return the answer in any order.
Рекомендации по теме
Комментарии
Автор

class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:

dict_of_seen_values = {}

for idx, value in enumerate(nums):

required_number = target - value



if required_number in dict_of_seen_values:
return [idx,

else:
dict_of_seen_values[value] = idx

maged_helmy