A very dumb way to AC by Python, but ez to understand


  • -3
    W
    class Solution:
    # @param {integer} n
    # @return {boolean}
    def isPowerOfTwo(self, n):
        if n == 1 or n == 2:
            return True
        for i in xrange(2, n // 2 + 1):
            if n % i != 0:
                break
            temp = n * 1.00
            while temp >= 1:
                temp /= i
                if temp == 1:
                    return True
        
        return False

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.