1346. Check If N and Its Double Exist
https://leetcode.com/problems/check-if-n-and-its-double-exist/
class Solution {
public:
bool checkIfExist(vector<int>& arr) {
unordered_set<int> s;
for (const auto a : arr) {
if (s.count(a * 2) || a % 2 == 0 && s.count(a / 2)) return true;
s.insert(a);
}
return false;
}
};Last updated