Ezvor

1. Two Sum

EasyArrays & Hashing Auto-judge ready

Given an array of integers nums and an integer target, return the indices (0-based) of the two numbers that add up to target. Exactly one valid answer exists and you may not use the same element twice. Return the two indices in ascending order.

Example 1:

Input:
4
2 7 11 15
9
Output:
0 1

Explanation: nums[0] + nums[1] = 2 + 7 = 9

Example 2:

Input:
3
3 2 4
6
Output:
1 2

I/O Format

Input: line 1 = n, line 2 = n space-separated integers, line 3 = target.
Output: the two indices separated by a space.

Constraints:

  • 2 ≤ n ≤ 10^4
  • -10^9 ≤ nums[i], target ≤ 10^9
  • Exactly one solution
Code
0 1