首页 > 代码库 > leetcode 231. Power of Two

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

 

leetcode 231. Power of Two