cs: add «2044. Count Number of Maximum Bitwise-OR Subsets»
URL: https://leetcode.com/problems/count-number-of-maximum-bitwise-or-subsets/ Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
5f10fcee50
commit
94390bbf94
1 changed files with 16 additions and 0 deletions
16
cs/count-number-of-maximum-bitwise-or-subsets.cs
Normal file
16
cs/count-number-of-maximum-bitwise-or-subsets.cs
Normal file
|
@ -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];
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue