码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode421

时间:2017-05-23 11:24:23      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:etc   efi   div   solution   https   for   number   dma   amp   

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

leetcode421

标签:etc   efi   div   solution   https   for   number   dma   amp   

原文地址:http://www.cnblogs.com/asenyang/p/6892905.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!