package leetcode;

/**
 * https://leetcode.com/problems/binary-number-with-alternating-bits/
 */
public class Problem693 {
    public boolean hasAlternatingBits(int n) {
        // TODO
        return false;
    }

    public static void main(String[] args) {
        Problem693 prob = new Problem693();
        System.out.println(prob.hasAlternatingBits(5)); // true
        System.out.println(prob.hasAlternatingBits(7)); // false
        System.out.println(prob.hasAlternatingBits(11)); // false
        System.out.println(prob.hasAlternatingBits(10)); // true
        System.out.println(prob.hasAlternatingBits(36)); // false
    }
}

@@ -175,30 +175,68 @@
     
-// TODO%0A        return
+String s = Integer.toBinaryString(n);%0A        boolean zero =
  fal
@@ -247,228 +247,333 @@
     
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem693 prob = new Problem693();%0A        System.out.println(prob.hasAlternatingBits(5)); // true%0A        System.out.println(prob.hasAlternatingBits(7)); //
+for (int i = 0; i %3C s.length(); i++) %7B%0A            if (i == 0) %7B%0A                if (s.charAt(i) == '0') %7B%0A                    zero = false;%0A                %7D else %7B%0A                    zero = true;%0A                %7D%0A            %7D else %7B%0A                if (zero && s.charAt(i) != '0') %7B%0A                    return
  false
+;
 %0A   
@@ -581,65 +581,102 @@
     
-System.out.println(prob.hasAlternatingBits(11)); //
+        %7D%0A                if (!zero && s.charAt(i) != '1') %7B%0A                    return
  false
+;
 %0A   
@@ -684,130 +684,92 @@
     
-System.out.println(prob.hasAlternatingBits(10)); // true%0A        System.out.println(prob.hasAlternatingBits(36)); // false
+        %7D%0A                zero = !zero;%0A            %7D%0A        %7D%0A        return true;
 %0A   

Solve problem 693