Skip to main content

Two Sum

EasyArrays & Strings

Given an array of integers nums and an integer target, return the indices of the two numbers that add up to target. Each element may only be used once.

Example:

Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Explanation: nums[0] + nums[1] = 2 + 7 = 9

Constraints:

  • 2 <= nums.length <= 10^4
  • -10^9 <= nums[i] <= 10^9
  • Exactly one solution exists