Re: [闲聊] 每日leetcode

楼主: DJYOMIYAHINA (通通打死)   2025-07-31 21:50:41
一开始往DP想 没仔细想还以为会到O(N^2)
但仔细想了之后
在同一个idx结尾的subarrays element-wise or起来最多只有32种可能而已
所以能行
def subarrayBitwiseORs(self, arr: List[int]) -> int:
st = set()
st2 = set()
for num in arr:
st3 = set([num])
st.add(num)
for item in st2:
st3.add(item|num)
st.add(item|num)
st2 = st3.copy()
return len(st)

Links booklink

Contact Us: admin [ a t ] ucptt.com