题目在这:https://leetcode-cn.com/problems/power-of-three/
思路分析:
判断一个数是不是由3的N次方得到的。数量级很大,暴力必然超时。
可以让所给的数不断的除以3.看最后能不能得到1。
比如 27/3=9/3=3/3=1 。 15/3=5/3=浮点数
完整代码:
class Solution:
def isPowerOfThree(self, n: int) -> bool:
while n >= 1:
if n == 1:
return True
n /= 3
return False