leetcode 231. Power of Two

Given an integer, write a function to determine if it is a power of two.

class Solution {
public:
    bool isPowerOfTwo(int n) {
        int num = 0;
        while (n > 0) {
            if (n &1) num++;
            n/=2;
        }
        if (num == 1) return true;
        return false;
    }
};
原文地址:https://www.cnblogs.com/pk28/p/7291798.html