Skip to content

Commit 07bd618

Browse files
authored
Update 421-maximum-xor-of-two-numbers-in-an-array.js
1 parent 7da1019 commit 07bd618

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

421-maximum-xor-of-two-numbers-in-an-array.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ const findMaximumXOR = function(nums) {
2121

2222
// another
2323

24+
/*
25+
26+
This algorithm's idea is:
27+
to iteratively determine what would be each bit of the final result from left to right.
28+
And it narrows down the candidate group iteration by iteration. e.g. assume input are a,b,c,d,...z, 26 integers in total.
29+
In first iteration, if you found that a, d, e, h, u differs on the MSB(most significant bit),
30+
so you are sure your final result's MSB is set. Now in second iteration,
31+
you try to see if among a, d, e, h, u there are at least two numbers make the 2nd MSB differs,
32+
if yes, then definitely, the 2nd MSB will be set in the final result.
33+
And maybe at this point the candidate group shinks from a,d,e,h,u to a, e, h.
34+
Implicitly, every iteration, you are narrowing down the candidate group,
35+
but you don't need to track how the group is shrinking, you only cares about the final result.
36+
37+
*/
2438
/*
2539
* @lc app=leetcode id=421 lang=javascript
2640
*

0 commit comments

Comments
 (0)