leetcode 231. Power of Two
阿新 • • 發佈:2018-04-17
code urn n) == nbsp mine elf integer brush
Given an integer, write a function to determine if it is a power of two.
class Solution(object): def isPowerOfTwo(self, n): """ :type n: int :rtype: bool """ #-4??? if n >= 1: return n & (n-1) == 0 else: return False
class Solution(object): def isPowerOfTwo(self, n): """ :type n: int :rtype: bool """ #-4??? c = 0 while n > 0: if n & 1: c += 1 n >>= 1 return c == 1
leetcode 231. Power of Two