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

Power of Two

时间:2015-12-10 16:30:43      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

class Solution {
public:
    bool isPowerOfTwo(int n) {
        //一定要处理n为0的情况
        if(n==0)
        return false;
        while(n%2==0)n=n/2;
        if (n==1)
        return true;
        else
        return false;
       
    }
};

Power of Two

标签:

原文地址:http://www.cnblogs.com/gofighting/p/5036223.html

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