326. Power of Three
Question
Given an integer
n, returntrueif it is a power of three. Otherwise, returnfalse.An integer
nis a power of three, if there exists an integerxsuch thatn == 3<sup>x</sup>.
Solution
与isPowerOfFour相同,如果n小于0则返回false。
如果n等于1则返回true。
递归,如果n可以整除3,则返回isPowerOfThree(n / 3)。
否则返回false。
Code
1 | class Solution { |
326. Power of Three
