###### 【Leetcode Algorithm】Power of Two
Given an integer, write a function to determine if it is a power of two.

public class Solution {
public boolean isPowerOfTwo(int n) {
//如果为0，则false
if(n==0){
return false;
}
//2^0=1
if(n==1){
return true;
}
//n为奇数则肯定不是，若是偶数则递归解决
if(n%2!=0){
return false;
}
else{
Solution s = new Solution();
return s.isPowerOfTwo(n/2);
}
}
}

public class Solution {
public boolean isPowerOfTwo(int n) {
//负数与0都不是
if(n<=0){
return false;
}
//如果n与n-1与运算之后不为0，则表明n的二进制数1的个数大于1，则判定肯定不是
else if((n&(n-1))!=0){
return false;
}
else{
return true;
}
}
}

#### leetcode 231: Power of Two

2015-07-07 05:01:24

#### 231. Power of Two [easy] (Python)

2016-05-05 14:47:26

#### LeetCode 231: Power of Two

2015-07-06 18:34:20

#### leetcode 231. Power of Two 判断是否为2的幂 Java

2016-04-23 16:38:25

#### Leetcode#231_power of two

2016-04-07 21:39:28

#### leetcode 231 Power of Two C++

2016-05-23 17:10:54

#### [LeetCode-231] Power of Two（判断一个数是不是2的若干次幂）

2015-09-14 19:59:45

#### LeetCode 之双指针 two pointers

2014-03-11 01:20:51

#### Leetcode-Algorithms Two Sum

2017-02-26 11:13:52

#### 随机的力量(1) - The power of random two choices

2015-11-01 00:43:52

## 不良信息举报

【Leetcode Algorithm】Power of Two