MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / Solution

Class Solution

Python/1_TwoSum.py:31–37  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29
30#Two-pass
31class Solution:
32 def twoSum(self, nums: List[int], target: int) -> List[int]:
33 d = {v:i for i,v in enumerate(nums)}
34 for i in range(len(nums)):
35 complement = target - nums[i]
36 if complement in d and d[complement]!=i:
37 return [i,d[complement]]
38
39'''
40Solution-2: Single Pass:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected