直接跳转:https://blog.csdn.net/Allenlzcoder/article/details/134566485
Solution1:
书中展示了很棒的思路:
关于异或的两个性质应该知道:
(1) X^X = 0;
(2) X^0 = X;
class Solution:
def sockCollocation(self, sockets: List[int]) -> List[int]:
x = y = n = 0
tag = 1
for item in sockets:
n ^= item
while n & tag == 0:
tag <<= 1
for item in sockets:
if item & tag == 0:
x ^= item
else:
y ^= item
return [x, y]