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

Power of Two

时间:2015-07-07 00:44:43      阅读:97      评论:0      收藏:0      [点我收藏+]

标签:

 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 };

 

Power of Two

标签:

原文地址:http://www.cnblogs.com/aguai1992/p/4625699.html

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