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

Class Solution

leetcode/1. Two Sum.py:9–16  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7'''
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.70

Calls

no outgoing calls

Tested by

no test coverage detected