java.lang.Object
g2001_2100.s2044_count_number_of_maximum_bitwise_or_subsets.Solution

public class Solution extends Object
2044 - Count Number of Maximum Bitwise-OR Subsets.<p>Medium</p> <p>Given an integer array <code>nums</code>, find the <strong>maximum</strong> possible <strong>bitwise OR</strong> of a subset of <code>nums</code> and return <em>the <strong>number of different non-empty subsets</strong> with the maximum bitwise OR</em>.</p> <p>An array <code>a</code> is a <strong>subset</strong> of an array <code>b</code> if <code>a</code> can be obtained from <code>b</code> by deleting some (possibly zero) elements of <code>b</code>. Two subsets are considered <strong>different</strong> if the indices of the elements chosen are different.</p> <p>The bitwise OR of an array <code>a</code> is equal to <code>a[0] **OR** a[1] **OR** ... **OR** a[a.length - 1]</code> ( <strong>0-indexed</strong> ).</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [3,1]</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> The maximum possible bitwise OR of a subset is 3. There are 2 subsets with a bitwise OR of 3:</p> <ul> <li> <p>[3]</p> </li> <li> <p>[3,1]</p> </li> </ul> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [2,2,2]</p> <p><strong>Output:</strong> 7</p> <p><strong>Explanation:</strong> All non-empty subsets of [2,2,2] have a bitwise OR of 2. There are 2<sup>3</sup> - 1 = 7 total subsets.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> nums = [3,2,1,5]</p> <p><strong>Output:</strong> 6</p> <p><strong>Explanation:</strong> The maximum possible bitwise OR of a subset is 7. There are 6 subsets with a bitwise OR of 7:</p> <ul> <li> <p>[3,5]</p> </li> <li> <p>[3,1,5]</p> </li> <li> <p>[3,2,5]</p> </li> <li> <p>[3,2,1,5]</p> </li> <li> <p>[2,5]</p> </li> <li> <p>[2,1,5]</p> </li> </ul> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 16</code></li> <li><code>1 <= nums[i] <= 10<sup>5</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • countMaxOrSubsets

      public int countMaxOrSubsets(int[] nums)