当前位置:网站首页>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 .边栏推荐
- Wechat applet parameter transfer
- Blood cases caused by < meta charset=UTF-8> -- Analysis of common character codes
- Fu Yingna: Yuan universe is the new generation of Internet!
- Implementation of jump connection of RESNET (pytorch)
- Asp. Net MVC, how can the controller in the folder jump to the controller in the root directory?
- Rhel8 patch package production
- C语言:结构体简单语法总结
- 如何查询版本的提交号
- Whole house WiFi solution: mesh router networking and ac+ap
- Is there any way for Youxuan database to check the log volume that the primary cluster transmits to the standby cluster every day?
猜你喜欢

UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0x90 in position 614: ordinal not in range(128)

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

HC06 HC05 BT

Copy products with one click from Taobao, tmall, 1688, wechat, jd.com, Suning, taote and other platforms to pinduoduo platform (batch upload baby details Interface tutorial)

Why are there so many unknowns when opengauss starts?

15.federation

MySQL gets the maximum value record by field grouping

10.回退消息

编译与链接

从淘宝,天猫,1688,微店,京东,苏宁,淘特等其他平台一键复制商品到拼多多平台(批量上传宝贝详情接口教程)
随机推荐
Pointer variables -printf%d and%p meaning
“蔚来杯“2022牛客暑期多校训练营2 H
Mmdetection preliminary use
How to execute insert into select from job in SQL client
Design of environment detection system based on STM32 and Alibaba cloud
The function "postgis_version" cannot be found when installing PostGIS
15.federation
opengauss预检查安装
Machine vision Series 2: vs DLL debugging
10.回退消息
The return value of the function is the attention of the pointer, the local variables inside the static limit sub function, and how the pointer to the array represents the array elements
MySQL gets the maximum value record by field grouping
2021 sist summer camp experience + record post of School of information, Shanghai University of science and technology
[kvm] install KVM
Array as function parameter -- pointer constant / constant pointer
15.federation
C language: getchar () and cache
Codeforces round 810 (Div. 2) d. rain (segment tree difference)
Blood cases caused by < meta charset=UTF-8> -- Analysis of common character codes
Fuzzy query of SQL