[InterviewBit] Min XOR value

Min XOR value

  • Time :
  • Space :
1
2
3
4
5
6
7
int Solution::findMinXor(vector<int> &A) {
sort(begin(A), end(A));
int res = INT_MAX;
for(int i = 0; i < A.size() - 1; i++) res = min(res, A[i] ^ A[i + 1]);
return res;
}

Author: Song Hayoung
Link: https://songhayoung.github.io/2022/10/20/PS/interviewbit/min-xor-value/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.