当前位置:网站首页>Not for 63 days. The biggest XOR
Not for 63 days. The biggest XOR
2022-07-29 04:16:00 【A little Ming】


class Solution {
// The highest bit number is 30
static final int HIGH_BIT = 30;
public int findMaximumXOR(int[] nums) {
int x = 0;
for (int k = HIGH_BIT; k >= 0; --k) {
Set<Integer> seen = new HashSet<Integer>();
// Will all pre^k(a_j) Put it in the hash table
for (int num : nums) {
// If you just want to keep it from the top to the bottom k The part that ends with two binary bits
// Just move it to the right k position
seen.add(num >> k);
}
// at present x From the top to the bottom k+1 The part that ends with two binary bits
// We will x Of the k Two binary positions are 1, That is to say x = x*2+1
int xNext = x * 2 + 1;
boolean found = false;
// enumeration i
for (int num : nums) {
if (seen.contains(xNext ^ (num >> k))) {
found = true;
break;
}
}
if (found) {
x = xNext;
} else {
// If you don't find one that satisfies the equation a_i and a_j, that x Of the k A binary bit can only be 0
// That is to say x = x*2
x = xNext - 1;
}
}
return x;
}
}
author :LeetCode-Solution
link :https://leetcode.cn/problems/ms70jA/solution/zui-da-de-yi-huo-by-leetcode-solution-hr7m/
source : Power button (LeetCode)
The copyright belongs to the author . Commercial reprint please contact the author for authorization , Non-commercial reprint please indicate the source .边栏推荐
猜你喜欢

Machine vision Series 2: vs DLL debugging

How to solve the problem of store ranking?

SVG--loading动画

Problems encountered in vscode connection SSH

Installation and use of stm32cubemx (5.3.0)

Applet: Area scrolling, pull-down refresh, pull-up load more

2021 sist summer camp experience + record post of School of information, Shanghai University of science and technology

12. Priority queue and inert queue

11.备份交换机

编译与链接
随机推荐
Record of problems encountered in ROS learning
店铺排名问题,如何解决?
Applet: Area scrolling, pull-down refresh, pull-up load more
数据库SQL语句实现数据分解的函数查询
How to solve the problem of store ranking?
What the hell is this error? It doesn't affect the execution result, but it always reports errors when executing SQL... Connecting maxcomputer uses
C语言:枚举知识点总结
Machine vision series 3:vs2019 opencv environment configuration
Pointer of pointer???...
Incubator course design (April 12, 2021)
BIO、NIO、AIO的区别和原理
Implementation of jump connection of RESNET (pytorch)
安装postgis时报找不到“POSTGIS_VERSION”这个函数
不会就坚持68天吧 狒狒吃香蕉
When defining an array, the size must be constant
MySQL gets the maximum value record by field grouping
请问为什么我进行mysql数据update时,kafka中采集到的是先删除原纪录(op d)再新增新
The principle of inverse Fourier transform (IFFT) in signal processing
C语言:浅谈各种复杂的声明
C语言力扣第61题之旋转链表。双端队列与构造循环链表