ntree.ai

Two Sum

easysolvedattempted

Given an array of integers nums and an integer target, return the indexes of the two numbers that add up to target.

Each input has exactly one solution, and the same element may not be used twice.

The answer may be returned in any order.

Example 1:

Input:  nums = [11, 2, 15, 7, 8, 1], target = 10
Output: [1, 4]
Explanation: nums[1] + nums[4] == 2 + 8 == 10.

Constraints:

  • 2 <= length of nums <= 10^5
  • -10^9 <= nums[i] <= 10^9
  • -10^9 <= target <= 10^9
def twoSum(nums: list[int], target: int) -> list[int]:
pass
 

Press Visualise to step through your code.