当前位置:网站首页>不会就坚持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)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。边栏推荐
- Value transmission and address transmission of C language, pointer of pointer
- Codeforces Round #810 (Div. 2) D. Rain (线段树差分)
- Interview notes of a company
- View partition table format
- 力扣面试题17.04 消失的数字||260.只出现一次的数字(内含位运算知识点)
- Data mining -- Introduction to the basis of association analysis (Part 1)
- How to set the SQL execution timeout for flick SQL
- Svg -- loading animation
- I. creation and constraint of MySQL table
- 全屋WiFi方案:Mesh路由器组网和AC+AP
猜你喜欢

Fu Yingna: Yuan universe is the new generation of Internet!

Data mining -- code implementation of association analysis example (Part 2)

mmdetection初步使用

Basic configuration of BGP - establish peers and route announcements

力扣面试题17.04 消失的数字||260.只出现一次的数字(内含位运算知识点)

Press the missing number of interview question 17.04 | | 260. the number that appears only once (including bit operation knowledge points)

Some problems about pointers
![[kvm] create virtual machine from kickstart file](/img/0e/292ccb6862e29d948ad6ece86b7945.png)
[kvm] create virtual machine from kickstart file

开课!看smardaten如何分解复杂业务场景

Lua language (stm32+2g/4g module) and C language (stm32+esp8266) methods of extracting relevant data from strings - collation
随机推荐
Fu Yingna: Yuan universe is the new generation of Internet!
Mmdetection preliminary use
Do you have a boss to help me check whether the parameter configuration of the Flink SQL connection Kafka authentication Kerberos is wrong
有一种密码学专用语言叫做ASN.1
Deep understanding of browser caching mechanism (HTTP)
HCIP BGP
Fuzzy query of SQL
Data mining -- Introduction to the basis of association analysis (Part 1)
Rhel8 patch package production
GBase 8a特殊场景下屏蔽 ODBC 负载均衡方式?
SVG--loading动画
[原理] 横向渗透的几种方式
C language to achieve three chess game (detailed explanation)
Lua语言(stm32+2G/4G模块)和C语言(stm32+esp8266)从字符串中提取相关数据的方法-整理
Interview notes of a company
MySQL gets the maximum value record by field grouping
Install the laser of ROS_ scan_ Problems encountered in match library (I)
Three tier architecture of enterprise network
Safari's compatibility with Z-index
How to write the filter conditions of data integration and what syntax to use? SQL syntax processing bizdate can not be