- 先想到的是有沒有辦法透過 bitwise operation 來判斷,發現無法
- 看相鄰位置有沒有一樣的,最直覺就是用字串來判斷 => 可以利用 Python 的 built-in function
bin來把數字轉為 binary 字串
Python3 solution:
1 | def hasAlternatingBits(self, n: int) -> bool: |
bin 來把數字轉為 binary 字串Python3 solution:
1 | def hasAlternatingBits(self, n: int) -> bool: |
1 會互相抵銷)Python3 solution:
1 | def singleNumber(self, nums: List[int]) -> int: |
Update your browser to view this website correctly. Update my browser now