LeeCode-Power of Two

Given an integer, write a function to determine if it is a power of two.

 

 1 bool isPowerOfTwo(int n)
 2 {
 3     if(n<=0)
 4         return false;
 5     
 6     if(n==1)
 7         return true;
 8     bool judge=false;
 9     while(n>1)
10     {
11         if(n%2==0)
12         {
13             n=n/2;
14         }
15         else
16         {
17             return false;
18         }
19     }
20 
21     if(n==0)
22         return true;
23 }

 

posted @ 2015-07-20 09:27  vpoet  阅读(150)  评论(0编辑  收藏  举报