package leetcode;

import java.util.HashSet;
import java.util.Set;

/**
 * https://leetcode.com/problems/bitwise-ors-of-subarrays/
 */
public class Problem898 {
    public int subarrayBitwiseORs(int[] A) {
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < A.length; i++) {
            int or = A[i];
            set.add(or);
            for (int j = i + 1; j < A.length; j++) {
                set.add(A[j]);
                or |= A[j];
                set.add(or);
            }
        }
        return set.size();
    }

    public static void main(String[] args) {
        Problem898 prob = new Problem898();
        System.out.println(prob.subarrayBitwiseORs(new int[]{0})); // 1
        System.out.println(prob.subarrayBitwiseORs(new int[]{1, 1, 2})); // 3
        System.out.println(prob.subarrayBitwiseORs(new int[]{1, 2, 4})); // 6
        System.out.println(prob.subarrayBitwiseORs(new int[]{1, 2, 4, 5})); // 7
    }
}

@@ -195,24 +195,71 @@
 (int%5B%5D A) %7B%0A
+        Set%3CInteger%3E answer = new HashSet%3C%3E();%0A
         Set%3C
@@ -351,21 +351,42 @@
     
-int or = A%5Bi%5D
+Set%3CInteger%3E tmp = new HashSet%3C%3E()
 ;%0A  
@@ -391,34 +391,36 @@
             
-set
+tmp
 .add(
-or
+A%5Bi%5D
 );%0A         
@@ -435,36 +435,15 @@
 int 
-j = i + 1; j %3C A.length; j++
+a : set
 ) %7B%0A
@@ -462,535 +462,135 @@
     
-set
+tmp
 .add(A%5B
-j%5D);%0A                or %7C= A%5Bj%5D;%0A                set.add(or);%0A            %7D%0A        %7D%0A        return set.size(
+i%5D %7C a);%0A            %7D%0A            answer.addAll(tmp
 );%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem898 prob = new Problem898();%0A        System.out.println(prob.subarrayBitwiseORs(new int%5B%5D%7B0%7D)); // 1%0A        System.out.println(prob.subarrayBitwiseORs(new int%5B%5D%7B1, 1, 2%7D)); // 3%0A        System.out.println(prob.subarrayBitwiseORs(new int%5B%5D%7B1, 2, 4%7D)); // 6%0A        System.out.println(prob.subarrayBitwiseORs(new int%5B%5D%7B1, 2, 4, 5%7D)); // 7
+    set = tmp;%0A        %7D%0A        return answer.size();
 %0A   

Solve problem 898