326. Power of Three【E】【81】

来源:互联网 发布:不破坏数据做活动分区 编辑:程序博客网 时间:2024/06/05 06:53


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

Follow up:
Could you do it without using any loop / recursion?

Credits:
Special thanks to @dietpepsi for adding this problem and creating all test cases.


Subscribe to see which companies asked this question






class Solution(object):    def isPowerOfThree(self, n):        if n == 0:            return False        if n == 1:            return True        if n % 3 != 0:            return False        return self.isPowerOfThree(n/3)                        '''这个方法就比较流氓了,找到32位最大的3的幂        if n <= 0:            return False        else:            return 1162261467 % n == 0        '''                #while n > 0:                                    """        :type n: int        :rtype: bool        """        


0 0
原创粉丝点击