File tree 2 files changed +34
-0
lines changed
2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 708
708
895|[ Maximum Frequency Stack] ( ./0895-maximum-frequency-stack.js ) |Hard|
709
709
896|[ Monotonic Array] ( ./0896-monotonic-array.js ) |Easy|
710
710
897|[ Increasing Order Search Tree] ( ./0897-increasing-order-search-tree.js ) |Easy|
711
+ 898|[ Bitwise ORs of Subarrays] ( ./0898-bitwise-ors-of-subarrays.js ) |Medium|
711
712
901|[ Online Stock Span] ( ./0901-online-stock-span.js ) |Medium|
712
713
905|[ Sort Array By Parity] ( ./0905-sort-array-by-parity.js ) |Easy|
713
714
909|[ Snakes and Ladders] ( ./0909-snakes-and-ladders.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 898. Bitwise ORs of Subarrays
3
+ * https://leetcode.com/problems/bitwise-ors-of-subarrays/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given an integer array arr, return the number of distinct bitwise ORs of all the non-empty
7
+ * subarrays of arr.
8
+ *
9
+ * The bitwise OR of a subarray is the bitwise OR of each integer in the subarray. The bitwise
10
+ * OR of a subarray of one integer is that integer.
11
+ *
12
+ * A subarray is a contiguous non-empty sequence of elements within an array.
13
+ */
14
+
15
+ /**
16
+ * @param {number[] } arr
17
+ * @return {number }
18
+ */
19
+ var subarrayBitwiseORs = function ( arr ) {
20
+ const results = new Set ( ) ;
21
+ let previous = new Set ( ) ;
22
+
23
+ for ( const num of arr ) {
24
+ const current = new Set ( [ num ] ) ;
25
+ for ( const prev of previous ) {
26
+ current . add ( prev | num ) ;
27
+ }
28
+ previous = current ;
29
+ previous . forEach ( val => results . add ( val ) ) ;
30
+ }
31
+
32
+ return results . size ;
33
+ } ;
You can’t perform that action at this time.
0 commit comments