aboutsummaryrefslogtreecommitdiff
path: root/count_num_max_or_subset.py
diff options
context:
space:
mode:
Diffstat (limited to 'count_num_max_or_subset.py')
-rw-r--r--count_num_max_or_subset.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/count_num_max_or_subset.py b/count_num_max_or_subset.py
index 02aa433..c19e4e1 100644
--- a/count_num_max_or_subset.py
+++ b/count_num_max_or_subset.py
@@ -2,13 +2,13 @@
from collections import Counter
"""
-given an integer array 'nums', find the maximum possible bitwise OR of a
+given an integer array 'nums', find the maximum possible bitwise or of a
subset of 'nums' and return the number of different non-empty subsets with
-the maximum bitwise OR. an array 'a' is a subset of an array 'b' if 'a' can
-be obtained from 'b' by deleting some (possibly 0) elements of 'b'. two
+the maximum bitwise or. an array 'a' is a subset of an array 'b' if 'a' can
+be obtained from 'b' by deleting some (possibly zero) elements of 'b'. two
subsets are considered different if the indices of the elements chosen are
-different. the bitwose OR of an array 'a' is equal to 'a[0] | a[1] | ... |
-a[n]' (0-indexed)
+different. the bitwise or of an array 'a' is equal to 'a[0] | a[1] | ... |
+a[a.length - 1]'
"""
@@ -19,14 +19,14 @@ class Solution(object):
:rtype: int
"""
dp = Counter([0])
- for n in nums:
- for i, j in list(dp.items()):
- dp[i | n] += j
+ for i in nums:
+ for k, v in dp.items():
+ dp[k | i] += v
return dp[max(dp)]
if __name__ == "__main__":
obj = Solution()
- print(obj.countMaxOrSubsets([3, 1]))
- print(obj.countMaxOrSubsets([2, 2, 2]))
- print(obj.countMaxOrSubsets([3, 2, 1, 5]))
+ print(obj.countMaxOrSubsets(nums=[3, 1]))
+ print(obj.countMaxOrSubsets(nums=[2, 2, 2]))
+ print(obj.countMaxOrSubsets(nums=[3, 2, 1, 5]))