-
Notifications
You must be signed in to change notification settings - Fork 7
/
Program.cs
32 lines (31 loc) · 831 Bytes
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using System.Collections.Generic;
using System.Linq;
namespace MaximumXOROfTwoNumbersInAnArray
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
static int FindMaximumXOR(int[] nums)
{
int max = 0, mask = 0;
for (int i = 31; i >= 0; i--)
{
mask |= 1 << i;
var set = new HashSet<int>();
foreach (var num in nums)
set.Add(mask & num);
int temp = max | (1 << i);
foreach (var num in set)
{
if (set.Contains(temp ^ num))
max = Math.Max(temp, max);
}
}
return max;
}
}
}