每日一题力扣231 啊这

给定一个整数,编写一个函数来判断它是否是 2 的幂次方。

 

class Solution:
    def isPowerOfTwo(self, n: int) -> bool:
        while n>1:
            n/=2
        return n==1

 

posted @ 2021-03-10 12:44  小千北同学超爱写代码  阅读(40)  评论(0编辑  收藏  举报