Easy · Arrays & hashing

Two Sum

You are given a list of whole numbers, nums, and a number, target. Two of the numbers add up to target. Return the positions (indexes) of those two numbers.

  • There is always exactly one such pair.
  • You may not use the same position twice, though the same value can appear twice.
  • The two indexes can be returned in either order.
nums   = [2, 7, 11, 15]
target = 9

→ [0, 1]   (2 + 7 = 9)
Record your take

3 ways to solve it.