leetcode421
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的更多相关文章
- [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 ...
随机推荐
- Django restfull规范
一. 什么是RESTful REST与技术无关,代表的是一种软件架构风格,REST是Representational State Transfer的简称,中文翻译为“表征状态转移” REST从资源的角 ...
- C++轮子队 敏捷冲刺
团队Github地址:https://github.com/Pryriat/2048.git 敏捷开发——第1天 Alpha阶段第1次Scrum Meeting 敏捷开发起始时间 2018/10/27 ...
- JS兼容性汇总
1. Frame (1)问题:在IE中可以用window.top.frameId和window.top.frameName来得到该Frame所代表的Window,Firefox中只能用window ...
- QT画图
if (0) { QApplication a(argv, args); QGraphicsScene scene; scene.setSceneRect(-300,-300,600,600); sc ...
- jgit - java实现git操作
在做一个项目中需要用到远程仓库,本来想使用svn的,但是svn的java api网上的资料很少,而且与git相比,svn显得笨重且不方便,因此放弃了svn转而使用git.java git api - ...
- Shell 参数(1)
shell 中参数相关: ./a.sh a b c d $# 是传给脚本的参数个数 $0 是脚本本身的名字 $1 是传递给该shell脚本的第一个参数 $2 是传递给该shell脚本的第二个参数 $@ ...
- matlab中求逆矩阵的高斯消元法实现的代码
function qiuni =INV_GET(a)N=length(a);M=eye(N);%得到上三角矩?for i=1:N max=a(i,i); A=i; for j=i+1:N if(abs ...
- 在django中使用logging
转:http://www.tuicool.com/articles/IV3meeE logging django使用python的内置模块logging来管理自己的日志,logging中四个重要的概念 ...
- rpm -Uvh 升级时的陷阱
问题现象 用rpm -Uvh升级后,原先的一个软链接被删除了,而采用先rpm -e 卸载rpm包,再rpm -ivh 安装包的方法,这个软链接还在.这个软链接是在rpm包安装的时候建立,也只有在rpm ...
- vs2015 c++ _findnext 报错
定位 _findnext(hFile,&fileinfo) 报错. 错误 :0x00007FFC70CB0B2D (ntdll.dll)处(位于 Cutton_Dlg.exe 中)引发的异常: ...