Can you solve this real interview question? Power of Two - Given an integer n, return true if it is a power of two. Otherwise, return false. An integer n is a power of two, if there exists an integer x such that n == 2x. Example 1: Input: n = 1 Ou
//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...
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...