1346. Check If N and Its Double Exist 發表於 2023-02-13 | 分類於 leetcode problemsolutionoption 1 - hash table123456789101112131415class Solution {public: bool checkIfExist(vector<int>& arr) { int n = arr.size(); unordered_set<int> s; for(int i=0;i<n;++i){ if(s.find(arr[i]*2)!=s.end()) return true; if(arr[i]%2==0 && s.find(arr[i]/2)!=s.end()) return true; s.insert(arr[i]); } return false; }}; analysis time complexity O(nlogn) space complexity O(1)