Skip to content

Commit 493f5ba

Browse files
authored
Update maximum-xor-with-an-element-from-array.cpp
1 parent 5506872 commit 493f5ba

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

C++/maximum-xor-with-an-element-from-array.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Solution {
5858
return a[2] < b[2];
5959
});
6060
vector<int> result(size(queries));
61-
Trie trie(32 - __builtin_clz(max_val));
61+
Trie trie(bit_length(max_val));
6262
int j = 0;
6363
for (const auto& q : queries) {
6464
int i = q[0], x = q[1], m = q[2];
@@ -69,4 +69,9 @@ class Solution {
6969
}
7070
return result;
7171
}
72+
73+
private:
74+
int bit_length(int x) {
75+
return x != 0 ? 32 - __builtin_clz(x) : 1;
76+
}
7277
};

0 commit comments

Comments
 (0)