-
Notifications
You must be signed in to change notification settings - Fork 382
Closed
Description
LeetCode Username
Thejaswini_k_m
Problem Number, Title, and Link
Bug Category
Problem description
Bug Description
The function returns the wrong indices for some inputs.
Steps:
Input: [3,2,4], target = 6 → Expected [1,2] but got [0,1].
Expected: Correct indices of the numbers that sum to the target.
Language Used for Code
Python/Python3
Code used for Submit/Run operation
class Solution:
def twoSum(self, nums, target):
hashmap = {}
for i, num in enumerate(nums):
diff = target - num
if diff in hashmap:
return [hashmap[diff], i]
hashmap[num] = iExpected behavior
Case 1
Case 2
Case 3
Input
nums =
[2,7,11,15]
target =
9
Output
[0,1]
Expected
[0,1]
Screenshots
No response
Additional context
No response
Metadata
Metadata
Assignees
Labels
No labels