garvitcoder

leetcode problem

Jun 20th, 2026
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. class Solution:
  2. def twoSum(self, nums: list[int], target: int) -> list[int]:
  3. # We try to use a dictionary to map numbers to their index
  4. seen = {}
  5.  
  6. for i, num in enumerate(nums):
  7. # Bug 1 & 2: Math and logic error here
  8. complement = num - target
  9.  
  10. # Bug 3: Checking the wrong dictionary state
  11. if complement in seen():
  12. return [seen[complement], i]
  13.  
  14. # Bug 4: Storing the wrong key-value relationship
  15. seen[i] = num
  16.  
  17. # Bug 5: Missing fallback return statement
  18.  
Advertisement
Add Comment
Please, Sign In to add comment