Two Sum
Easy
array
hash-table
Problem Description
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice.
Input Format
First line contains n (array size) and target
Second line contains n integers
Output Format
Two integers representing the indices (0-indexed)
Constraints
2 <= nums.length <= 10^4
-10^9 <= nums[i] <= 10^9
-10^9 <= target <= 10^9
Sample Input/Output
Input:
4 9 2 7 11 15
Output:
0 1
Explanation
Because nums[0] + nums[1] = 2 + 7 = 9, we return [0, 1].
Solution Hints
100
Points
Points
2000ms
Time Limit
Time Limit
256MB
Memory Limit
Memory Limit
Code Editor
Register to Access Code Editor
Create a free account to solve coding problems and track your progress.
Register Now