From 94390bbf9452c2092c00f387e967430b7bddc3f6 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Fri, 18 Oct 2024 11:01:20 +0200 Subject: [PATCH] =?UTF-8?q?cs:=20add=20=C2=AB2044.=20Count=20Number=20of?= =?UTF-8?q?=20Maximum=20Bitwise-OR=20Subsets=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit URL: https://leetcode.com/problems/count-number-of-maximum-bitwise-or-subsets/ Signed-off-by: Matej Focko --- cs/count-number-of-maximum-bitwise-or-subsets.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 cs/count-number-of-maximum-bitwise-or-subsets.cs 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]; + } +}