231. Power of Two

来源:互联网 发布:mac 任务管理工具 编辑:程序博客网 时间:2024/06/05 03:40

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

class Solution {public:    bool isPowerOfTwo(int n) {        int s = 0;        if(n < 1) return false;        for(int i = 0; i < 32; ++i){            if(n & 1)                ++s;            n >>= 1;        }        if(s == 1)            return true;        return false;    }};
0 0
原创粉丝点击