题解 | #两数之和#
两数之和
http://www.nowcoder.com/practice/20ef0972485e41019e39543e8e895b7f
class Solution { public: /** * * @param numbers int整型vector * @param target int整型 * @return int整型vector */ vector<int> twoSum(vector<int>& numbers, int target) { unordered_map<int, int> m; for(int i=0; i<numbers.size(); i++){ if(m.count(target-numbers[i])){ return {m[target-numbers[i]]+1, i+1}; } else{ m[numbers[i]] = i; } } return {}; // write code here } };