[leetcode oj 231]Power of Two

来源:互联网 发布:java单向链表 编辑:程序博客网 时间:2024/04/28 21:32

Given an integer, write a function to determine if it is a power of two.
ok。。。一样的。。。

class Solution {public:    bool isPowerOfTwo(int n) {        if(n <= 0)            return false;        if(n == 1)            return true;        if(n % 2 == 0)        {            if(n == 2)                return true;            return isPowerOfTwo(n / 2);        }        return false;    }};
0 0
原创粉丝点击