码迷,mamicode.com
首页 > 其他好文 > 详细

LeeCode-Power of Two

时间:2015-07-20 10:37:32      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:

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 }

 

LeeCode-Power of Two

标签:

原文地址:http://www.cnblogs.com/vpoet/p/4660533.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!