标签:
1 class Solution { 2 public: 3 vector<int> twoSum(vector<int>& nums, int target) { 4 map<int, int> m; 5 vector<int> res; 6 for (size_t i = 0; i < nums.size(); ++i) m[nums[i]] = i; 7 for (size_t i = 0; i < nums.size(); ++i) { 8 int gap = target - nums[i]; 9 if (m.find(gap) != m.end() && m[gap] != i) { 10 res.push_back(i); 11 res.push_back(m[gap]); 12 break; 13 } 14 } 15 return res; 16 } 17 };
标签:
原文地址:http://www.cnblogs.com/shadowwalker9/p/5902543.html