class Solution(object):
# def isPowerOfThree(self, n):
# """
# :type n: int
# :rtype: bool
# """
# import math
# if n <= 0:
# return False
# # use round to check
# log_res = round(math.log(n, 3), 10)
# if log_res - int(log_res) > 0:
# return False
# return True
def isPowerOfThree(self, n):
max3pow = 1162261467
if n <= 0 or n > max3pow:
return False
return max3pow % n == 0
Download Power of Three.pyLeetcode 326 Power of Three problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.
Feedback is the most important part of any website.
If you have any query, suggestion or feedback, Please feel free to contact us.