231. Power of Two

来源:互联网 发布:淘宝卖家体检中心链接 编辑:程序博客网 时间:2024/05/16 04:10

一直除2

public class Solution {
    public boolean isPowerOfTwo(int n) {
        if(n==0)return false;
        if(n==1)return true;
        if(n%2==1)return false;
        while(n%2==0){
            n=n/2;
        }
        if(n==1)return true;
        else return false;
    }
}

0 0