leetcode 231. Power of Two

    bool isPowerOfTwo(int n) {
        if (n < 1) return false;
        int m = 1;
        for (int i = 0; i < 32; i++) {
            int j = n & m;
            if (j == n)
                return true;
            m = m << 1;
        }
        return false;
    }

 

posted on 2018-02-06 11:50  willaty  阅读(72)  评论(0编辑  收藏  举报

导航