You are viewing a single comment's thread. Return to all comments →
C++ solution works. Use hash function to solve it.
int pairs(int k, vector<int> arr) { int res = 0; unordered_set<int> sta; for(int i = 0; i < arr.size(); i++) sta.insert(arr[i]); for(auto it = sta.begin(); it != sta.end(); it++) if(sta.find(*it+k) != sta.end()) res++; return res; }
Pairs
You are viewing a single comment's thread. Return to all comments →
C++ solution works. Use hash function to solve it.