forked from liuyubobobo/Play-Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
40 lines (30 loc) · 795 Bytes
/
main.cpp
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
35
36
37
38
39
40
/// Source : https://leetcode.com/problems/bitwise-ors-of-subarrays/description/
/// Author : liuyubobobo
/// Time : 2018-09-02
#include <iostream>
#include <vector>
#include <unordered_set>
using namespace std;
/// Frontier Hash Set
/// Time Complexity: O(n*log(max_number))
/// Space Complexity: O(n*log(max_number))
class Solution {
public:
int subarrayBitwiseORs(vector<int>& A) {
unordered_set<int> res;
unordered_set<int> frontier;
unordered_set<int> cur;
for(int a: A){
cur.clear();
cur.insert(a);
for(int x: frontier)
cur.insert(x | a);
res.insert(cur.begin(), cur.end());
frontier = cur;
}
return res.size();
}
};
int main() {
return 0;
}