diff --git a/cs/count-number-of-maximum-bitwise-or-subsets.cs b/cs/count-number-of-maximum-bitwise-or-subsets.cs new file mode 100644 index 0000000..079b894 --- /dev/null +++ b/cs/count-number-of-maximum-bitwise-or-subsets.cs @@ -0,0 +1,16 @@ +public class Solution { + public int CountMaxOrSubsets(int[] nums) { + var dp = new int[1 << 17]; + dp[0] = 1; + + var max = 0; + foreach (var num in nums) { + for (int i = max; i >= 0; --i) { + dp[i | num] += dp[i]; + } + max |= num; + } + + return dp[max]; + } +}