Given an integer, write a function to determine if it is a power of three.
这个是Power of two 的兄弟题,他的兄弟可以用Bit Manipulation做,但是它不可以
这里用了DFS搜索做
public class Solution {
public boolean isPowerOfThree(int n) {
if(n == 0)
return false;
if(n == 1)
return true;
return n%3 == 0 && isPowerOfThree(n/3);
}
}