Class Solution
java.lang.Object
g0801_0900.s0898_bitwise_ors_of_subarrays.Solution
898 - Bitwise ORs of Subarrays.<p>Medium</p>
<p>We have an array <code>arr</code> of non-negative integers.</p>
<p>For every (contiguous) subarray <code>sub = [arr[i], arr[i + 1], ..., arr[j]]</code> (with <code>i <= j</code>), we take the bitwise OR of all the elements in <code>sub</code>, obtaining a result <code>arr[i] | arr[i + 1] | ... | arr[j]</code>.</p>
<p>Return the number of possible results. Results that occur more than once are only counted once in the final answer</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> arr = [0]</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Explanation:</strong> There is only one possible result: 0.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> arr = [1,1,2]</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong></p>
<pre><code> The possible subarrays are [1], [1], [2], [1, 1], [1, 2], [1, 1, 2].
These yield the results 1, 1, 2, 1, 3, 3.
There are 3 unique values, so the answer is 3.
</code></pre>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> arr = [1,2,4]</p>
<p><strong>Output:</strong> 6</p>
<p><strong>Explanation:</strong> The possible results are 1, 2, 3, 4, 6, and 7.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 5 * 10<sup>4</sup></code></li>
<li><code>0 <= nums[i] <= 10<sup>9</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
subarrayBitwiseORs
public int subarrayBitwiseORs(int[] arr)
-