Advertisement
dimon-torchila

Untitled

Mar 17th, 2023
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. class Solution {
  2. public:
  3. int findMaximumXOR(vector<int>& nums) {
  4. int mask = 0, ans = 0;
  5. for(int i = 31; i >= 0; --i){
  6. mask |= (1 << i);
  7. set<int> s;
  8. for(int j = 0; j < nums.size(); ++j){
  9. s.insert(nums[j] & mask);
  10. }
  11. int cand = ans |(1 << i);
  12. for(auto x : s){
  13. if(s.find(x ^ cand) != s.end()){
  14. ans = cand;
  15. break;
  16. }
  17. }
  18. }
  19. return ans;
  20. }
  21. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement