【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) {
        if (n <= 0) return false;
        
        if (n == 1) return true;
        
        if (n % 2 != 0) return false;
        
        else return isPowerOfTwo(n/2);
        
        return true;
    }
};

 

posted on 2016-09-10 08:14  医生工程师  阅读(101)  评论(0编辑  收藏  举报

导航