class Solution {
public:
bool isPowerOfThree(int n) {
if(!n) return false;
while(n%3==0){n /= 3;}
if(n==1) return true;
else return false;
}
};
思路;
可以枚举;也可以直接/3求。
class Solution {
public:
bool isPowerOfThree(int n) {
if(!n) return false;
while(n%3==0){n /= 3;}
if(n==1) return true;
else return false;
}
};
思路;
可以枚举;也可以直接/3求。