public class Solution {
public int FindMaximumXOR(int[] nums) {
int max = , mask = ;
for (int i = ; i >= ; i--)
{
mask = mask | ( << i);
HashSet<int> set = new HashSet<int>();
foreach (int num in nums)
{
set.Add(num & mask);
}
int tmp = max | ( << 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的更多相关文章

  1. [Swift]LeetCode421. 数组中两个数的最大异或值 | Maximum XOR of Two Numbers in an Array

    Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...

随机推荐

  1. java mybatis XML文件中大于号小于号转义(转载)

    因为这个是xml文件不允许出现类似“>”这样的字符 用了转义字符把>和<替换掉,然后就没有问题了. XML转义字符 字段 符号 说明 &lt ; < 小于号 & ...

  2. Elasticsearch 文档专用

    ES安装等操作 http://blog.csdn.net/cnweike/article/details/33736429 https://www.elastic.co/guide/cn/elasti ...

  3. LeetCode OJ:Product of Array Except Self(除己之外的元素乘积)

    Given an array of n integers where n > 1, nums, return an array output such that output[i] is equ ...

  4. js的作用是临时修改 表单Action提交的地址,因为 又有新的动作需要把表单参数提交到 新的servlet中,这点很重要

    JavaScript可以临时修稿 form表单的提交地址

  5. 日常生活小技巧 -- 惠普 Windows10 进入安全模式

    今天手贱,是真的很贱.将用户模式从管理员组改为标准用户 方法是:WIN+R 打开 control userpasswords2 然后出现了用户账户控制,你要允许此应用对你的设备进行更改吗?最关键的是没 ...

  6. 使用 nvm 管理多版本 node

    首先,使用下面的命令来安装 nvm $ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | b ...

  7. warning MSB8004: Output Directory does not end with a trailing slash.

    当在VC里编译时,发现这个警告,就是说设置的目录参数不是以反斜杠结束的目录名称,如下: 1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V ...

  8. Leetcode 1019. Next Greater Node In Linked List

    单调栈的应用. class Solution: def nextLargerNodes(self, head: ListNode) -> List[int]: stack = [] ret = ...

  9. Compiling OpenGL games with the Flash C Compiler (FlasCC)

    Compiling OpenGL games with the Flash C Compiler (FlasCC) In this article I show how to use the Flas ...

  10. ASP调用存储过程访问SQL Server

     ASP调用存储过程访问SQL Server 2011-02-15 10:22:57 标签:asp 数据库 sQL 存储过程 Server ASP和存储过程(Stored Procedures)的文章 ...