当前位置:网站首页>不会就坚持63天吧 最大的异或
不会就坚持63天吧 最大的异或
2022-07-29 04:13:00 【一只小小明】
class Solution {
// 最高位的二进制位编号为 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>();
// 将所有的 pre^k(a_j) 放入哈希表中
for (int num : nums) {
// 如果只想保留从最高位开始到第 k 个二进制位为止的部分
// 只需将其右移 k 位
seen.add(num >> k);
}
// 目前 x 包含从最高位开始到第 k+1 个二进制位为止的部分
// 我们将 x 的第 k 个二进制位置为 1,即为 x = x*2+1
int xNext = x * 2 + 1;
boolean found = false;
// 枚举 i
for (int num : nums) {
if (seen.contains(xNext ^ (num >> k))) {
found = true;
break;
}
}
if (found) {
x = xNext;
} else {
// 如果没有找到满足等式的 a_i 和 a_j,那么 x 的第 k 个二进制位只能为 0
// 即为 x = x*2
x = xNext - 1;
}
}
return x;
}
}
作者:LeetCode-Solution
链接:https://leetcode.cn/problems/ms70jA/solution/zui-da-de-yi-huo-by-leetcode-solution-hr7m/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
边栏推荐
- [kvm] common commands
- Is the array name a pointer
- The table of antd hides the pager when there is only one page
- Summary on the thought of double pointer
- Object detection: object_ Detection API +ssd target detection model
- How to write SQL statements about field conversion
- Methods of using multiple deformations on an element
- (.*?) regular expression
- Pointer constant and constant pointer
- Why are there so many unknowns when opengauss starts?
猜你喜欢
Compilation and linking
BGP的基础配置---建立对等体、路由宣告
Is the array name a pointer
伏英娜:元宇宙就是新一代互联网!
LDP -- label distribution protocol
Summary on the thought of double pointer
The solution of porting stm32f103zet6 program to c8t6+c8t6 download program flash timeout
[kvm] create virtual machine from kickstart file
AssertionError(“Torch not compiled with CUDA enabled“)
MPU6050
随机推荐
A little understanding of pointer, secondary pointer, wild pointer, pointer as function return value
MySQL gets the maximum value record by field grouping
[paper translation] vectornet: encoding HD maps and agent dynamics from vectorized representation
(.*?) regular expression
Blood cases caused by < meta charset=UTF-8> -- Analysis of common character codes
C语言:typedef知识点总结
Lua language (stm32+2g/4g module) and C language (stm32+esp8266) methods of extracting relevant data from strings - collation
The function "postgis_version" cannot be found when installing PostGIS
优炫数据库有办法查到主集群每天传给备集群的日志量吗?
The output comparison function of Tim is introduced in detail through PWM breathing lamp and PWM controlled DC motor
Const read only variable constant
请问,在sql client中,执行insert into select from job时,如何单
Object detection: object_ Detection API +ssd target detection model
Who can elaborate on the semi consistent read under mysqlrc and how to reduce the deadlock probability?
Big manufacturers finally can't stand "adding one second", and companies such as Microsoft, Google meta propose to abolish leap seconds
初识C语言(3)
通过js来实现一元二次方程的效果,输入a,b,c系数后可计算出x1和x2的值
View partition table format
基于STM32和阿里云的环境检测系统设计
Ma Zhixing entered the mass production of front loading, starting with the self-developed domain controller?