-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.cpp
More file actions
27 lines (26 loc) · 841 Bytes
/
Copy path1.cpp
File metadata and controls
27 lines (26 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*******************************************************************************
> File Name: 1.cpp
> Author: sillyplus
> Mail: oi_boy@sina.cn
> Created Time: Tue Mar 15 01:14:59 2016
*******************************************************************************/
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
vector<int> ret;
map<int, int> mp;
for (int i = 0; i < nums.size(); ++i) {
mp[nums[i]] = i;
}
for (int i = 0; i < nums.size(); ++i) {
if (mp.find(target - nums[i]) != mp.end()) {
if (mp[target - nums[i]] != i) {
ret.push_back(i);
ret.push_back(mp[target - nums[i]]);
return ret;
}
}
}
return ret;
}
};