-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetCode-1.cpp
More file actions
28 lines (25 loc) · 775 Bytes
/
LeetCode-1.cpp
File metadata and controls
28 lines (25 loc) · 775 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
28
/*************************************************************************
> File Name: LeetCode-1.cpp
> Author: ltw
> Mail: 3245849061@qq.com
> Created Time: Sat 16 May 2020 07:44:22 PM CST
************************************************************************/
#include <iostream>
using namespace std;
class Solution {
public:
unordered_map<int, int> h;
vector<int> twoSum(vector<int>& nums, int target) {
vector<int> ret;
for (int i = 0; i < nums.size(); i++) {
if (h.find(target - nums[i]) == h.end()) {
h[nums[i]] = i;
continue;
}
ret.push_back(h[target - nums[i]]);
ret.push_back(i);
break;
}
return ret;
}
};