-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTwoSum.cpp
36 lines (32 loc) · 843 Bytes
/
TwoSum.cpp
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
#include <iostream>
#include <vector>
#include <unordered_map>
std::vector<int> getIndices() {
int target = 6;
std::vector<int> nums{3,2,4};
std::vector<int> returnVec;
std::unordered_map<int,int> diffMap;
diffMap[target - nums[0]] = 0;
for(int i = 1; i < nums.size(); i++) {
if(diffMap.count(nums[i]) != 0) {
// std::cout << "Match" << std::endl;
returnVec.push_back(diffMap[nums[i]]);
returnVec.push_back(i);
return returnVec;
}
else {
// std::cout << "No Match" << std::endl;
diffMap[target - nums[i]] = i;
}
}
std::vector<int> notWork{0,0};
return notWork;
// std::vector<int> notWork{0,0};
// return notWork;
}
int main() {
std::vector<int> indices = getIndices();
std::cout << indices[0] << std::endl;
std::cout << indices[1] << std::endl;
return 0;
}