File tree Expand file tree Collapse file tree
0421.Maximum XOR of Two Numbers in an Array Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ class Solution :
2+ def findMaximumXOR (self , nums : List [int ]) -> int :
3+ max = 0
4+ mask = 0
5+ for i in range (30 , - 1 , - 1 ):
6+ current = 1 << i
7+ # 期望的二进制前缀
8+ mask = mask ^ current
9+ # 在当前前缀下, 数组内的前缀位数所有情况集合
10+ _set = set ()
11+ for num in nums :
12+ _set .add (num & mask )
13+ # 期望最终异或值的从右数第i位为1, 再根据异或运算的特性推算假设是否成立
14+ flag = max | current
15+ for prefix in _set :
16+ if prefix ^ flag in _set :
17+ max = flag
18+ break
19+ return max
Original file line number Diff line number Diff line change 768768│ └── Solution.java
769769├── 0421.Maximum XOR of Two Numbers in an Array
770770│ ├── README.md
771- │ └── Solution.java
771+ │ ├── Solution.java
772+ │ └── Solution.py
772773├── 0423.Reconstruct Original Digits from English
773774│ └── Solution.cpp
774775├── 0427.Construct Quad Tree
You can’t perform that action at this time.
0 commit comments