当前位置:网站首页>不会就坚持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)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。边栏推荐
- Is there any way for Youxuan database to check the log volume that the primary cluster transmits to the standby cluster every day?
- Big manufacturers finally can't stand "adding one second", and companies such as Microsoft, Google meta propose to abolish leap seconds
- Wechat applet parameter transfer
- [原理] 横向渗透的几种方式
- 有一种密码学专用语言叫做ASN.1
- MPU6050
- Pointer of pointer???...
- Zhihuijun, a genius of Huawei, made a modular mechanical keyboard, which caused an earthquake in the geek circle. Netizens: This is the real customization
- %s. %c, character constant, string constant, const char*, pointer array, string array summary
- 为什么opengauss启动的时候这么多的unknown?
猜你喜欢

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

First knowledge of C language (3)

Lua language (stm32+2g/4g module) and C language (stm32+esp8266) methods of extracting relevant data from strings - collation

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

The principle of inverse Fourier transform (IFFT) in signal processing

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

Svg -- loading animation

Note: restframe work records many to one tables, how to serialize in that table (reverse query)

Basic configuration of BGP - establish peers and route announcements

Class starts! See how smardaten decomposes complex business scenarios
随机推荐
Data mining -- code implementation of association analysis example (Part 2)
MySQL Part 4 (end)
Is the browser multi process or single process?
“蔚来杯“2022牛客暑期多校训练营1 J Serval and Essay(启发式合并)
Pointer variables -printf%d and%p meaning
大佬们flink的JDBC SQL Connector现在不支持所有的数据库吗,例如vertica?
[Openstack] keystone,nova
AssertionError(“Torch not compiled with CUDA enabled“)
How to write the filter conditions of data integration and what syntax to use? SQL syntax processing bizdate can not be
全屋WiFi方案:Mesh路由器组网和AC+AP
Differences and principles of bio, NiO and AIO
安装postgis时报找不到“POSTGIS_VERSION”这个函数
There is a special cryptology language called asn.1
Const read only variable constant
How to set the SQL execution timeout for flick SQL
“蔚来杯“2022牛客暑期多校训练营2 H
有没有大佬帮我看下flink sql连接kafka认证kerberos的参数配置是否有误
Asp. Net MVC, how can the controller in the folder jump to the controller in the root directory?
Beginner: array & String
Svg -- loading animation