Two Sum

Problem Given an array of integers and a target, return the indices of the two numbers that add up to the target. Exactly one valid pair exists and an element may not be used twice.

Input / Output

  • Input: integer array nums, integer target.
  • Output: the pair of indices [i, j] with nums[i] + nums[j] == target.

Constraints

  • 2 <= n <= 10^4; exactly one solution; each input has one answer.

Example

  • nums = [2,7,11,15], target = 9 → [0,1] (2 + 7 = 9).
added …
LeaderboardSalaryAccount