LeetCode 898. Bitwise ORs of Subarrays

题目链接:https://leetcode.com/problems/bitwise-ors-of-subarrays/description/

枚举以第i个数结尾的运算的所有情况。

class Solution {
public:
    int subarrayBitwiseORs(vector& A) {
        set s;
        set ans;
        s.insert(0);
        for(int i=0;i tmp;
            for(auto j: s)
            {
                ans.insert(j|A[i]);
                tmp.insert(j|A[i]);
            }
            tmp.insert(0);
            s=tmp;
        }
        return ans.size();
    }
};

 

你可能感兴趣的:(思维)