Skip to content

Commit fbee8ae

Browse files
authored
Update count-pairs-with-xor-in-a-range.py
1 parent f837138 commit fbee8ae

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Python/count-pairs-with-xor-in-a-range.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def count(nums, x):
1818
dp = collections.Counter(nums)
1919
while x:
2020
if x&1:
21-
result += sum(dp[(x^1)^k]*dp[k] for k in dp.iterkeys())//2 # current limit is 0...01*****, count xor pair with 0...00***** pattern
21+
result += sum(dp[(x^1)^k]*dp[k] for k in dp.iterkeys())//2 # current limit is xxxxx1*****, count xor pair with xxxxx0***** pattern
2222
dp = collections.Counter({k>>1: dp[k]+dp[k^1] for k in dp.iterkeys()})
2323
x >>= 1
2424
return result
@@ -49,7 +49,7 @@ def query(self, num, limit):
4949
bit = (limit>>i) & 1
5050
if bit:
5151
if curr in node:
52-
result += node[curr]["_count"] # current limit is 0...01*****, count xor pair with 0...00***** pattern
52+
result += node[0^curr]["_count"] # current limit is xxxxx1*****, count xor pair with xxxxx0***** pattern
5353
if bit^curr not in node:
5454
break
5555
node = node[bit^curr]

0 commit comments

Comments
 (0)