231. Power of Two

来源:互联网 发布:免费海关数据 编辑:程序博客网 时间:2024/05/24 00:56

题目:

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


原创粉丝点击