All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : June 24, 2024
Last updated : July 04, 2024
Related Topics : Array, Math, Bit Manipulation
Acceptance Rate : 79.33 %
Intuition: We can basically form any number less than or equal to numbers we have, so we can isolate their bits and take whichever are present
int maximumXOR(int* nums, int numsSize) {
int output = 0;
for (int i = 0; i < numsSize; i++) {
output |= nums[i];
}
return output;
}
class Solution {
public:
int maximumXOR(vector<int>& nums) {
int output = 0;
for (int num : nums) {
output |= num;
}
return output;
}
};
class Solution {
public int maximumXOR(int[] nums) {
int output = 0;
for (int num : nums) {
output |= num;
}
return output;
}
}
class Solution:
def maximumXOR(self, nums: List[int]) -> int:
output = 0
for num in nums :
output |= num
return output