loading…
Write two_sum(nums, target) that returns the indices of the two numbers that add up to target, as a list [i, j] with i < j. Exactly one answer exists; you may not use the same element twice.
two_sum([2, 7, 11, 15], 9) -> [0, 1]
two_sum([3, 2, 4], 6) -> [1, 2]
Stuck on the idea itself? The arrays & hashing lesson walks through the pattern from scratch.