-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitwiseORsOfSubarrays.js
More file actions
34 lines (28 loc) · 878 Bytes
/
Copy pathBitwiseORsOfSubarrays.js
File metadata and controls
34 lines (28 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// https://leetcode-cn.com/problems/bitwise-ors-of-subarrays/
var Test = require('./Common/Test');
var subarrayBitwiseORs = function (nums) {
// nums = [...new Set(nums)];
// console.log("subarrayBitwiseORs");
const result = new Set();
for (let i = 0; i < nums.length; i++) {
// console.log({ i });
let value = nums[i];
for (let j = i; j < nums.length; j++) {
// console.log({ j });
result.add(value |= nums[j]);
}
}
return result;
// return result.size;
};
function test(nums) {
Test.test(subarrayBitwiseORs, nums);
}
function testWithTestcase(id) {
Test.testWithTestcase(subarrayBitwiseORs, id);
}
// test([1, 1, 2]);
// test([1, 2, 4]);
// test([39, 19, 30, 56, 79, 50, 19, 70, 30]);
// https://leetcode-cn.com/submissions/detail/95169323/testcase/
testWithTestcase(95169323);