class Solution(object):
def isPowerOfThree(self, n):
return n > 0 and 1162261467 % n == 0
Python O(1) Solution 96.6%

Also you could use the following math approach to get the max 32 bit integer power of 'x' number:
pow( x,int( log(0x7FFFFFFF)/log(x) ) ).
In this case x= 3, 0x7FFFFFFF isthe maximum 32 bit integer and the change of base with log(0x7FFFFFFF)/log(x) = logx(0x7FFFFFFF) which yields the number to which you have to power 'x' to get the biggest 32 bit integer.
Note that int() returns the floor of a number passed as parameter.

