leetcode Two sum
two-sum_牛客网
https://www.nowcoder.com/practice/20ef0972485e41019e39543e8e895b7f?tpId=46&tqId=29177&tPage=1&rp=1&ru=/ta/leetcode&qru=/ta/leetcode/question-ranking
注意下标从1开始
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
unordered_map<int, int> m;
vector<int> v;
for(int i = 0; i < nums.size(); ++i)
{
int t = target - nums[i];
if(m.count(t) != 0)
{
v.push_back(m[t]);
v.push_back(i);
}
else {m[nums[i]] = i;}
}
return v;
}
};</int></int></int>