【位运算】3的幂

题目:

 

 

解答:

 1 class Solution {
 2 public:
 3     bool isPowerOfThree(int n) 
 4     {
 5         if (n < 1) 
 6         {
 7             return false;
 8         }
 9 
10         while (n % 3 == 0) 
11         {
12             n /= 3;
13         }
14 
15         return n == 1;
16     }
17 };

 

posted @ 2020-05-16 14:14  梦醒潇湘  阅读(301)  评论(0)    收藏  举报