00:00Ready when you are
Easy
Two Sum
The problem
Given an array of numbers and a target number, find two numbers in the array that add up to the target. Return the positions (indexes) of the two numbers. You can assume there's always exactly one answer, and you can't use the same number twice.
Examples
Input: nums = [2, 7, 11, 15], target = 9
Output: [0, 1]
Because nums[0] + nums[1] = 2 + 7 = 9, we return [0, 1].
Input: nums = [3, 2, 4], target = 6
Output: [1, 2]
Because nums[1] + nums[2] = 2 + 4 = 6, we return [1, 2].
Input: nums = [3, 3], target = 6
Output: [0, 1]
Because nums[0] + nums[1] = 3 + 3 = 6, we return [0, 1].
Start a session to use voice
solution.js
Tests
Run tests to check your solution
What you said
0Your thoughts will appear here
