Power of Two

来源:互联网 发布:数据挖掘与数据分析 编辑:程序博客网 时间:2024/06/05 04:33

题目:

Given an integer, write a function to determine if it is a power of two.

解题思路:

class Solution:
    # @param {integer} n
    # @return {boolean}
    def isPowerOfTwo(self, n):
        if n<=0:
            return False
        while n>=2:
            if n%2!=0:
                return False
            n = n/2
        return True
            
        

0 0
原创粉丝点击