Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def twoSum(self, nums: list[int], target: int) -> list[int]:
- # We try to use a dictionary to map numbers to their index
- seen = {}
- for i, num in enumerate(nums):
- # Bug 1 & 2: Math and logic error here
- complement = num - target
- # Bug 3: Checking the wrong dictionary state
- if complement in seen():
- return [seen[complement], i]
- # Bug 4: Storing the wrong key-value relationship
- seen[i] = num
- # Bug 5: Missing fallback return statement
Advertisement
Add Comment
Please, Sign In to add comment