2044. Count Number of Maximum Bitwise-OR Subsets Medium
1/**
2 * [2044] Count Number of Maximum Bitwise-OR Subsets
3 *
4 * Given an integer array nums, find the maximum possible bitwise OR of a subset of nums and return the number of different non-empty subsets with the maximum bitwise OR.
5 * An array a is a subset of an array b if a can be obtained from b by deleting some (possibly zero) elements of b. Two subsets are considered different if the indices of the elements chosen are different.
6 * The bitwise OR of an array a is equal to a[0] OR a[1] OR ... OR a[a.length - 1] (0-indexed).
7 *
8 * Example 1:
9 *
10 * Input: nums = [3,1]
11 * Output: 2
12 * Explanation: The maximum possible bitwise OR of a subset is 3. There are 2 subsets with a bitwise OR of 3:
13 * - [3]
14 * - [3,1]
15 *
16 * Example 2:
17 *
18 * Input: nums = [2,2,2]
19 * Output: 7
20 * Explanation: All non-empty subsets of [2,2,2] have a bitwise OR of 2. There are 2^3 - 1 = 7 total subsets.
21 *
22 * Example 3:
23 *
24 * Input: nums = [3,2,1,5]
25 * Output: 6
26 * Explanation: The maximum possible bitwise OR of a subset is 7. There are 6 subsets with a bitwise OR of 7:
27 * - [3,5]
28 * - [3,1,5]
29 * - [3,2,5]
30 * - [3,2,1,5]
31 * - [2,5]
32 * - [2,1,5]
33 *
34 * Constraints:
35 *
36 * 1 <= nums.length <= 16
37 * 1 <= nums[i] <= 10^5
38 *
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/count-number-of-maximum-bitwise-or-subsets/
43// discuss: https://leetcode.com/problems/count-number-of-maximum-bitwise-or-subsets/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48 pub fn count_max_or_subsets(nums: Vec<i32>) -> i32 {
49 0
50 }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57 use super::*;
58
59 #[test]
60 fn test_2044() {
61 }
62}
63
Back
© 2025 bowen.ge All Rights Reserved.