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:
Matej Focko 2024-10-18 11:01:20 +02:00
parent 5f10fcee50
commit 94390bbf94
Signed by: mfocko
SSH key fingerprint: SHA256:icm0fIOSJUpy5+1x23sfr+hLtF9UhY8VpMC7H4WFJP8

View 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];
}
}