Skip to content

Latest commit

 

History

History
91 lines (72 loc) · 1.78 KB

_2317. Maximum XOR After Operations .md

File metadata and controls

91 lines (72 loc) · 1.78 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


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

Solutions

C

int maximumXOR(int* nums, int numsSize) {
    int output = 0;
    for (int i = 0; i < numsSize; i++) {
        output |= nums[i];
    }
    return output;
}

C++

class Solution {
public:
    int maximumXOR(vector<int>& nums) {
        int output = 0;

        for (int num : nums) {
            output |= num;
        }

        return output;
    }
};

Java

class Solution {
    public int maximumXOR(int[] nums) {
        int output = 0;
        for (int num : nums) {
            output |= num;
        }

        return output;
    }
}

Python

class Solution:
    def maximumXOR(self, nums: List[int]) -> int:
        output = 0
        for num in nums :
            output |= num

        return output