当前位置:网站首页>不会就坚持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)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。边栏推荐
- SQL语句 关于字段转换怎么写
- Pointer constant and constant pointer
- Codeforces round 810 (Div. 2) d. rain (segment tree difference)
- 数据库SQL语句实现数据分解的函数查询
- 对一个元素使用多种变形的方法
- Blood cases caused by < meta charset=UTF-8> -- Analysis of common character codes
- How to execute insert into select from job in SQL client
- Const char* and char*, string constants
- The function "postgis_version" cannot be found when installing PostGIS
- Value transmission and address transmission of C language, pointer of pointer
猜你喜欢

STM32F103ZET6程序移植为C8T6+C8T6下载程序flash timeout的解决方案

BGP的基础配置---建立对等体、路由宣告

Object detection: object_ Detection API +ssd target detection model

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)

安装ros的laser_scan_matche库所遇到的问题(一)

小程序:区域滚动、下拉刷新、上拉加载更多

初识C语言(3)

The solution of porting stm32f103zet6 program to c8t6+c8t6 download program flash timeout

When array is used as a function parameter, it is better to use the array size as a function parameter

Ma Zhixing entered the mass production of front loading, starting with the self-developed domain controller?
随机推荐
Leftmost prefix principle of index
SQL server how to judge when the parameter received by the stored procedure is of type int?
数据库SQL语句实现数据分解的函数查询
C语言实现三子棋游戏(详解)
When defining an array, the size must be constant
数据源是SQL server ,我要配置日期字段 updateDate 最后两天日期的增量数据,做增
Asp.net MVC中文件夹中的控制器如何跳转到根目录的控制器中?
C语言:typedef知识点总结
BGP的基础配置---建立对等体、路由宣告
Database SQL statement realizes function query of data decomposition
优炫数据库有办法查到主集群每天传给备集群的日志量吗?
Blood cases caused by < meta charset=UTF-8> -- Analysis of common character codes
Value transmission and address transmission of C language, pointer of pointer
Problems encountered in vscode connection SSH
How to write SQL statements about field conversion
3. Solve pychart's error unresolved reference 'selenium' unresolved reference 'webdriver‘
Locally call tensorboard and Jupiter notebook on the server (using mobaxterm)
UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0x90 in position 614: ordinal not in range(128)
What the hell is this error? It doesn't affect the execution result, but it always reports errors when executing SQL... Connecting maxcomputer uses
MySQL Part 3