Bit Manipulation, Easy
Question
Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.
Example 1:
|
|
Example 2:
|
|
Example 3:
|
|
Example 4:
|
|
My Answer
|
|
Running time: O(n), n is the length bit of the given number, 15ms