LintCode:O(1)时间检测2的幂次

来源:互联网 发布:人员画像 公安大数据 编辑:程序博客网 时间:2024/05/12 22:12

LintCode:O(1)时间检测2的幂次

class Solution {    /*     * @param n: An integer     * @return: True or false     */    public boolean checkPowerOf2(int n) {        // write your code here        if(n <=0){            return false;        }        else{            if((n & (n-1)) == 0){                return true;            }        }        return false;    }};
0 0
原创粉丝点击