#C14810. Two Sum
Two Sum
Two Sum
Given an array of integers nums
and an integer target
, find the indices of the two numbers such that they add up to target
. You may assume that each input has exactly one solution and you may not use the same element twice.
Note: The indices should be returned using 0-based indexing. Formally, let nums be the array and i, j be the indices such that:
$$ nums[i] + nums[j] = target, \quad i \neq j $$
It is guaranteed that there is exactly one solution for each test case.
inputFormat
The first line contains an integer n
, the number of elements in the array.
The second line contains n
space-separated integers, representing the array nums
.
The third line contains an integer target
.
outputFormat
Output a pair of indices separated by a space corresponding to the positions in the array nums
whose values sum to target
.
4
2 7 11 15
9
0 1
</p>