原题描述:
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
给定一个数组,返回两个数在数组中的索引,使它们相加等于给定的目标值。
解题思路:使用map的key-value结构存放遍历过数组元素的值和下标,在map中直接查找,有插入到返回的vector中,没有插入到map。
1 | vector<int> twoSum(vector<int> &nums,int target) |