898. Bitwise ORs of Subarrays Medium
1/**
2 * [898] Bitwise ORs of Subarrays
3 *
4 * We have an array arr of non-negative integers.
5 * For every (contiguous) subarray sub = [arr[i], arr[i + 1], ..., arr[j]] (with i <= j), we take the bitwise OR of all the elements in sub, obtaining a result arr[i] | arr[i + 1] | ... | arr[j].
6 * Return the number of possible results. Results that occur more than once are only counted once in the final answer
7 *
8 * Example 1:
9 *
10 * Input: arr = [0]
11 * Output: 1
12 * Explanation: There is only one possible result: 0.
13 *
14 * Example 2:
15 *
16 * Input: arr = [1,1,2]
17 * Output: 3
18 * Explanation: The possible subarrays are [1], [1], [2], [1, 1], [1, 2], [1, 1, 2].
19 * These yield the results 1, 1, 2, 1, 3, 3.
20 * There are 3 unique values, so the answer is 3.
21 *
22 * Example 3:
23 *
24 * Input: arr = [1,2,4]
25 * Output: 6
26 * Explanation: The possible results are 1, 2, 3, 4, 6, and 7.
27 *
28 *
29 * Constraints:
30 *
31 * 1 <= nums.length <= 5 * 10^4
32 * 0 <= nums[i] <= 10^9
33 *
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/bitwise-ors-of-subarrays/
38// discuss: https://leetcode.com/problems/bitwise-ors-of-subarrays/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43 pub fn subarray_bitwise_o_rs(arr: Vec<i32>) -> i32 {
44 0
45 }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_898() {
56 }
57}
58
Back
© 2025 bowen.ge All Rights Reserved.