Count Good Subarrays
You are given an integer array nums.
A subarray is called good if the bitwise OR of all its elements is equal to at least one element present in that subarray.
Return the number of good subarrays in nums.
Here, the bitwise OR of two integers a and b is denoted by a | b.
Example 1
Input
nums = [4,2,3]Output
4The good subarrays are
[4], [2], [3], and [2, 3], so the answer is 4.Example 2
Input
nums = [1,3,1]Output
6Every subarray has a bitwise OR that is present in that subarray, so all 6 subarrays are good.
Constraints
- 1 <= nums.length <= 10^5
- 0 <= nums[i] <= 10^9