public class Solution { public int FindMaximumXOR(int[] nums) { int max = 0, mask = 0; for (int i = 31; i >= 0; i--) { mask = mask | (1 << i); HashSet<int> set = new HashSet<int>(); foreach (int num in nums) { set.Add(num & mask); } int tmp = max | (1 << i); foreach (int prefix in set) { if (set.Contains(tmp ^ prefix)) { max = tmp; break; } } } return max; } }
https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array/#/description
时间: 2024-10-12 16:16:35