Past Challenges
leetle
8. Two Sum
Difficulty: 71%
Time: 00:00
Write a function solve that finds two numbers in a list that add up to a target value. Return a list with their indices in order. If the target cannot be made, return an empty list.
Example: Input: [2, 7, 11, 15], target=9
Output: [0, 1]
Make sure you return your solution, don't print!
def solve(nums, target):
pass
Test Cases
- Test case 1: [2, 7, 11, 15], target=9
- Test case 2: [3, 2, 4], target=6
- Test case 3: [3, 3], target=6
- Test case 4: [1, 2, 3], target=6
- Test case 5: [], target=0
Attempts
- Attempt 1: Success
- Attempt 2: Failure