Two Sum

Problem Given an array nums and a target, return the indices of the two numbers that add up to the target. Exactly one solution exists, and you may not use the same element twice.

Input / Output

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

Constraints

  • 2 <= nums.length <= 10^4
  • Only one valid answer exists.
  • Values may be negative and may repeat.

Example

  • nums = [2,7,11,15], target = 9 -> [0,1]
added …
LeaderboardSalaryAccount