[InterviewBit] Diffk II

Diffk II

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
int Solution::diffPossible(const vector<int> &A, int B) {
unordered_set<int> us;
for(auto a : A) {
if(us.count(a+B) or us.count(a-B)) return true;
us.insert(a);
}
return false;
}

Author: Song Hayoung
Link: https://songhayoung.github.io/2022/09/26/PS/interviewbit/diffk-ii/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.