Two Sum / Hashmap

Problem

Return indices of two numbers summing to a target.

Input / Output

  • Input: an integer array nums and an integer target.
  • Output: the indices [i, j] of the two numbers that add up to target.

Constraints

  • 2 ≤ n ≤ 10^4
  • Exactly one valid pair is guaranteed.

Example

[2,7,11,15], 9 -> [0,1]
added …
LeaderboardSalaryAccount