Created
October 11, 2022 08:23
-
-
Save BoyanXu/f4caab422e4f34652a42cff52eec6e70 to your computer and use it in GitHub Desktop.
sol6.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <unordered_set> | |
#include <utility> | |
using namespace std; | |
class Solution { | |
public: | |
vector<pair<int,int>> doubleCheck(vector<int> V) { | |
unordered_set<int> H; | |
vector<pair<int,int>> K; | |
for (auto i : V) H.insert(i); | |
for (auto i : V) { | |
if (H.contains(2 * i)) { | |
K.push_back(make_pair(i, 2*i)); | |
} | |
} | |
return K; | |
} | |
}; | |
int main() { | |
vector<int> test1 = { 33, 12, 41, 6, 20, 10, 52, 34, 52, 27, 26 }; | |
Solution solution; | |
vector<pair<int,int>> output = solution.doubleCheck(test1); | |
for (auto p : output) { | |
cout << "(" << p.first << ", " << p.second << ")\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment