Power of Three
Problem: Power of Three
My solution is a brute-force method. The constant time solution can be found here.
Code in Python:
class Solution(object):
def isPowerOfThree(self, n):
"""
:type n: int
:rtype: bool
"""
if n <= 0: return False
elif n == 1: return True
elif n % 3: return False
else: return self.isPowerOfThree(n / 3)