java.lang.Object
g0601_0700.s0693_binary_number_with_alternating_bits.Solution

public class Solution extends Object
693 - Binary Number with Alternating Bits.<p>Easy</p> <p>Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> n = 5</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> The binary representation of 5 is: 101</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> n = 7</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong> The binary representation of 7 is: 111.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> n = 11</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong> The binary representation of 11 is: 1011.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= n <= 2<sup>31</sup> - 1</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • hasAlternatingBits

      public boolean hasAlternatingBits(int n)