326. Power of Three
Question
Given an integer
n
, returntrue
if it is a power of three. Otherwise, returnfalse
.An integer
n
is a power of three, if there exists an integerx
such 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