2044. Count Number of Maximum Bitwise-OR Subsets

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 2044

class Solution:
    def countMaxOrSubsets(self, nums: List[int]) -> int:
        n = len(nums)
        res = 0
        mx = 0
        for mask in range(1 << n):
            t = 0
            for i, v in enumerate(nums):
                if (mask >> i) & 1:
                    t |= v
            if mx < t:
                mx = t
                res = 1
            elif mx == t:
                res += 1
        return res