NC61两数之和
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
vector<int>v;
unordered_map<int,int>map;
for(int i=0;i<nums.size();i++){
auto it=map.find(target-nums[i]);
if(it!=map.end()){
//先插下标小的
//题目下标从1开始-需要+1
v.push_back(it->second+1);
v.push_back(i+1);
}else{
map[nums[i]]=i;
}
}
return v;
}
};