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

posted on 2017-03-14 10:58  gechen  阅读(79)  评论(0编辑  收藏  举报

导航