MCPcopy Create free account
hub / github.com/Jack-Lee-Hiter/AlgorithmsByPython / twoSum

Method twoSum

leetcode/1. Two Sum.py:10–16  ·  view source on GitHub ↗
(self, nums, target)

Source from the content-addressed store, hash-verified

8
9class Solution():
10 def twoSum(self, nums, target):
11 hashdict = {}
12 for i, item in enumerate(nums):
13 if (target - item) in hashdict:
14 return (hashdict[target - item], i)
15 hashdict[item] = i
16 return (-1, -1)
17s = Solution()
18print(s.twoSum([2, 7, 11, 15], 9))

Callers 1

1. Two Sum.pyFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected