/
rnekrasov
/
Python
Обзор
Документация
Войти
/
rnekrasov
/
Python
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
two_num.py
26 строк
691 B
Rafal Zawadzki
PEP8 Flake8 fixes
02 окт 2018, 22:18
02 окт 2018, 22:18
7304bf0
Код
Авторство
О чём код?
"""Author Anurag Kumar (mailto:anuragkumarak95@gmail.com) Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may not use the same element twice. Example: Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1]. """ def twoSum(nums, target): chk_map = {} for index, val in enumerate(nums): compl = target - val if compl in chk_map: indices = [chk_map[compl], index] print(indices) return [indices] else: chk_map[val] = index return False