File tree 2 files changed +36
-1
lines changed
2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,706 LeetCode solutions in JavaScript
1
+ # 1,707 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1567
1567
2040|[ Kth Smallest Product of Two Sorted Arrays] ( ./solutions/2040-kth-smallest-product-of-two-sorted-arrays.js ) |Hard|
1568
1568
2042|[ Check if Numbers Are Ascending in a Sentence] ( ./solutions/2042-check-if-numbers-are-ascending-in-a-sentence.js ) |Easy|
1569
1569
2043|[ Simple Bank System] ( ./solutions/2043-simple-bank-system.js ) |Medium|
1570
+ 2044|[ Count Number of Maximum Bitwise-OR Subsets] ( ./solutions/2044-count-number-of-maximum-bitwise-or-subsets.js ) |Medium|
1570
1571
2047|[ Number of Valid Words in a Sentence] ( ./solutions/2047-number-of-valid-words-in-a-sentence.js ) |Easy|
1571
1572
2053|[ Kth Distinct String in an Array] ( ./solutions/2053-kth-distinct-string-in-an-array.js ) |Medium|
1572
1573
2071|[ Maximum Number of Tasks You Can Assign] ( ./solutions/2071-maximum-number-of-tasks-you-can-assign.js ) |Hard|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 2044. Count Number of Maximum Bitwise-OR Subsets
3
+ * https://leetcode.com/problems/count-number-of-maximum-bitwise-or-subsets/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given an integer array nums, find the maximum possible bitwise OR of a subset of nums and return
7
+ * the number of different non-empty subsets with the maximum bitwise OR.
8
+ *
9
+ * An array a is a subset of an array b if a can be obtained from b by deleting some (possibly zero)
10
+ * elements of b. Two subsets are considered different if the indices of the elements chosen are
11
+ * different.
12
+ *
13
+ * The bitwise OR of an array a is equal to a[0] OR a[1] OR ... OR a[a.length - 1] (0-indexed).
14
+ */
15
+
16
+ /**
17
+ * @param {number[] } nums
18
+ * @return {number }
19
+ */
20
+ var countMaxOrSubsets = function ( nums ) {
21
+ const maxOr = nums . reduce ( ( or , num ) => or | num , 0 ) ;
22
+ let count = 0 ;
23
+
24
+ backtrack ( 0 , 0 ) ;
25
+
26
+ return count ;
27
+
28
+ function backtrack ( index , currentOr ) {
29
+ if ( currentOr === maxOr ) count ++ ;
30
+ for ( let i = index ; i < nums . length ; i ++ ) {
31
+ backtrack ( i + 1 , currentOr | nums [ i ] ) ;
32
+ }
33
+ }
34
+ } ;
You can’t perform that action at this time.
0 commit comments