# How to add two numbers without add()

I’m going to simulate the whole adding process by bit manipulation:

``````def add(a, b):
if not b:
return a

sum = a ^ b  # Just add without carry
carry = (a & b) << 1  # Just carry without add

and it works 🙂

## 我想试一试

### Status

Listensmileagree, and then do whatever the fuck you were gonna do anyway.

# Find medians from a slide window

`a = [1,2,3,12,-5,33]k = 3b = [2,3,3,12]b`

# Maximum XOR of Two Numbers in an Array

Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231.

Find the maximum result of ai XOR aj, where 0 ≤ ij < n.

Could you do this in O(n) runtime?

Example:

`Input: [3, 10, 5, 25, 2, 8] Output: 28 Explanation: The maximum result is 5 ^ 25 = 28.`

result += any(result ^ 1 ^ p in prefixes for p in prefixes)

``````class Solution:
def findMaximumXOR(self, nums: List[int]) -> int:
result = 0

for i in range(32)[::-1]:
result <<= 1
prefixes = {num >> i for num in nums}
result += any(result ^ 1 ^ p in prefixes for p in prefixes)

return result

``````