1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| public class Solution { public boolean isPowerOfThree(int n) { if (n == 1) { return true; }
if (n < 3) { return false; }
while (n / 3 > 0) { if (n % 3 != 0) { return false; } n = n / 3; if(n == 1){ return true; } }
return false; } }
|