Bitwise ORs of Subarrays
We have an arrayA
of non-negative integers.
For every (contiguous) subarrayB = [A[i], A[i+1], ..., A[j]]
(withi <= j
), we take the bitwise OR of all the elements inB
, obtaining a resultA[i] | A[i+1] | ... | A[j]
.
Return the number of possible results. (Results that occur more than once are only counted once in the final answer.)
Example 1:
Example 2:
Example 3:
Note:
1
<
= A.length
<
= 50000
0
<
= A[i]
<
= 10^9
分析
需要存当前的bit or的set,新来的数和所有数bit or,再加上自己。每次cur都union 入res
Last updated