I am implementing an algorithm to find the pair of integers in the given array which have minimum XOR value.
Ex:
Input:
0 2 5 7
Output:
2 (value of 0 XOR 2).
Then bellow is my solution:
public int findMinXor(List<int> A)
{
var min = int.MaxValue;
for (int i = 0; i < A.Count - 1; i++)
{
for (int j = i + 1; j < A.Count; j++)
{
var tmp = A[i] ^ A[j];
if (tmp < min)
{
min = tmp;
}
}
}
return min;
}
What should I do to improve the solution (clean code, performance, DRY,...)? Any help are appriciate!