Power of Two

 1 class Solution {
 2 public:
 3     bool isPowerOfTwo(int n) {
 4         int temp;
 5         if(n==0)
 6             return false;
 7         if(n==1)
 8             return true;
 9         else 
10         {
11             while(temp!=1)
12             {
13                 temp=n/2;
14                 if(temp*2!=n)
15                     return false;
16                 n/=2;
17             }
18             return true;
19         }
20     }
21 };

 

posted @ 2015-07-06 23:17  阿怪123  阅读(120)  评论(0)    收藏  举报