Special thanks to@dietpepsifor adding this problem and creating all test cases. Subscribeto see which companies asked this question Hide Tags Math Show Similar Problems 题意: 给一个整数n,判断是否是3的幂 1classSolution {2public:3boolisPowerOfThree(intn) {4doubleans = log(n) / log(3);5d...
//Solution2: Recursion.publicstaticbooleanisPowerOfThree(intn) {if(n <= 0)returnfalse;if(n == 1)returntrue;if(n % 3 == 0)returnisPowerOfThree(n/3);elsereturnfalse; } Solution3: Using Log Function. (logab = logcb / logca) publicbooleanisPowerOfThree(intn) {if(n <= 0)returnf...