Please solve the programming task below using a self-contained code snippet in a markdown code block.

Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.
 
Please complete the following python code precisely:
```python
class Solution:
    def hasAlternatingBits(self, n: int) -> bool:
```