Power of Two

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

posted @ 2015-12-10 15:35  雪之灵  阅读(131)  评论(0编辑  收藏  举报