722. Maximum Subarray VI

Code(Language:C++)
class Solution {
public:
    /**
     * @param nums: the array
     * @return: the max xor sum of the subarray in a given array
     */
    int maxXorSubarray(vector<int> &nums) {
        // write code here
        const int size = nums.size();
        if(size == 0){
            return 0; 
        }
        vector<int> prefix(size + 1, 0);
        for(int i = 0; i < size; i++){
            prefix[i + 1] = prefix[i] ^ nums[i]; 
        }
        int maxV = INT_MIN;
        for(int i = 0; i <= size; i++){
            for(int j = i + 1; j <= size; j++){
                maxV = max(maxV, prefix[i] ^ prefix[j]); 
            }
        }
        return maxV; 
    }
};

Comments

Popular posts from this blog

算法的比较