-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.cpp
More file actions
43 lines (35 loc) · 826 Bytes
/
1.cpp
File metadata and controls
43 lines (35 loc) · 826 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <vector>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
vector <int> nums = {2,5,5,11};
int target = 10;
unordered_map <int, int>hashmap;
for (size_t i = 0; i < nums.size(); i++)
{
if(hashmap.find( target - nums[i] ) == hashmap.end()){
hashmap[nums[i]] = i;
}
else{
cout << hashmap[target - nums[i]] <<" "<< i<<endl;
}
}
cout << "result?";
return 0;
}
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
unordered_map <int, int>hashmap;
for (int i = 0; i < nums.size(); i++)
{
if(hashmap.find( target - nums[i] ) == hashmap.end()){
hashmap[nums[i]] = i;
}
else{
return {hashmap[target - nums[i]], i};
}
}
}
};