Two Sum

Write the code, see it run, pass the checks.

The problem

  • easy
  • Code

Write twoSum(nums, target): return the indices [i, j], with i < j, of the two numbers in nums that add up to target, or null if no two do. A number can't be paired with itself, and there's at most one answer. The checks include 100,000 numbers, so trying every pair is too slow.

Your code must pass

  • Finds the two numbers that add up to the target
  • Doesn't use the same number twice
  • Returns null when no two numbers add up
  • Is fast enough for 100,000 numbers