package leetcode;

/**
 * https://leetcode.com/problems/binary-gap/
 */
public class Problem868 {
    public int binaryGap(int N) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem868 prob = new Problem868();
        System.out.println(prob.binaryGap(22)); // 2
        System.out.println(prob.binaryGap(5)); // 2
        System.out.println(prob.binaryGap(6)); // 1
        System.out.println(prob.binaryGap(8)); // 0
    }
}

@@ -137,38 +137,44 @@
     
-// TODO%0A        return
+int n = N;%0A        int max =
  0;%0A    
 %7D%0A%0A 
@@ -173,308 +173,401 @@
     
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem868 prob = new Problem868();%0A        System.out.println(prob.binaryGap(22)); // 2%0A        System.out.println(prob.binaryGap(5)); // 2%0A        System.out.println(prob.binaryGap(6)); // 1%0A        System.out.println(prob.binaryGap(8)); // 0
+int gap = 0;%0A        int count = 0;%0A        while (n %3E 0) %7B%0A            int i = n & 1;%0A            if (i == 1) %7B%0A                count++;%0A                if (count %3E= 2) %7B%0A                    max = Math.max(max, gap + 1);%0A                %7D%0A                gap = 0;%0A            %7D else if (count %3E= 1) %7B%0A                gap++;%0A            %7D%0A            n %3E%3E= 1;%0A        %7D%0A        return max;
 %0A   

Solve problem 868