← 返回 meta 的题目列表Two Sum
类型:online_judge
Given an array of integers nums and an integer target, return the 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. For example, given nums = [2, 7, 11, 15], target = 9, because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1].
Input
An integer array nums, and an integer target.
Output
Two integers, the indices of the two numbers
Example
Example 1:
Input: nums = [2, 7, 11, 15], target = 9
Output: [0, 1]
Example 2:
Input: nums = [3, 2, 4], target = 6
Output: [1, 2]
Example
Input
[2, 7, 11, 15] 9