类似的题解详见:
leetcode_232. Power of Two分析
leetcode_342. Power of Four分析
题目链接
【题目】
Given an integer, write a function to determine if it is a power of three.
【分析】
解法1:
一般做法
class Solution {
public:
bool isPowerOfThree(int n) {
while (n && n % 3 == 0) {
n /= 3;
}
return n ==