###### tags: `LeetCode`,`Python3`,`Easy` # 231. Power of Two ### **題目連結:** [**Power of Two**](https://leetcode.com/problems/power-of-two/description/?envType=daily-question&envId=2024-02-19) ### **解題方向** * 判斷某數是不是2的指數,只要一直將該值除2即可,最終如果是1的話就代表是 ### **完整程式碼** ```Python= class Solution: def isPowerOfTwo(self, n: int) -> bool: if n==0 :return False while n%2==0:n/=2 return n==1 ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up