moonlightshadow123
5/30/2017 - 2:50 PM

231. Power of Two

  1. Power of Two
class Solution(object):
    def isPowerOfTwo(self, n):
        """
        :type n: int
        :rtype: bool
        """
        if n == 0: 
            return False
        while n & 1 == 0:
            n = n >> 1
        return n == 1

https://leetcode.com/problems/power-of-two/

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