勤恳仙人掌

文章
5
资源
0
加入时间
3年0月27天

LeetCode第 326 题:3的幂(C++)

326. 3的幂 - 力扣(LeetCode)常规方法:如果 n 是 3 的幂,那么一直对 3 取模,最后一定会得到 1 。class Solution {public: bool isPowerOfThree(int n) { while(n > 1){ if(n % 3) return false; n /= 3; } return n == 1; }};进阶:你能