MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / twoSum

Function twoSum

other/two_sum.py:14–29  ·  view source on GitHub ↗

:type nums: List[int] :type target: int :rtype: List[int]

(nums, target)

Source from the content-addressed store, hash-verified

12from __future__ import print_function
13
14def twoSum(nums, target):
15 """
16 :type nums: List[int]
17 :type target: int
18 :rtype: List[int]
19 """
20 chk_map = {}
21 for index, val in enumerate(nums):
22 compl = target - val
23 if compl in chk_map:
24 indices = [chk_map[compl], index]
25 print(indices)
26 return [indices]
27 else:
28 chk_map[val] = index
29 return False

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected