693. Binary Number with Alterntive Bits
s1. n<<1 + n should be all 1s.
s2. similar to s1 but more pythonic
s3. check by bit
Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.
Example 1:
1 | Input: 5 |
Example 2:
1 | Input: 7 |
Example 3:
1 | Input: 11 |
Example 4:
1 | Input: 10 |
Soulution:
1 | class Solution: |
1 | class Solution: |
1 | class Solution: |