2401. Longest Nice Subarray

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2401

class Solution:
    def longestNiceSubarray(self, nums: List[int]) -> int:
        res = j = mask = 0
        for i, x in enumerate(nums):
            while mask & x:
                mask ^= nums[j]
                j += 1
            res = max(res, i - j + 1)
            mask |= x
        return res