← All problems

Two Sum

Easy arrayshash maps LeetCode ↗
Given an array of integers nums and an integer target, return indices of the two numbers that add up to target. Each input has exactly one solution.

Hints (0/3 revealed)

Log in to reveal hints progressively.

Complexity

Time O(n), Space O(n)

Common pitfalls

  • Returning values instead of indices
  • Using the same element twice

Your solution

Log in to save your code and track progress.