231. Power of Two

Given an integer, write a function to determine if it is a power of two.

题目含义:判断一个数是否是2的n次方

 1     public boolean isPowerOfTwo(int n) {
 2         // int cnt = 0;
 3         // while (n > 0) {
 4         //     cnt += (n & 1);
 5         //     n >>= 1;
 6         // }
 7         // return cnt == 1;    
 8         
 9         // 方法二
10         if (n<=0) return false;
11         return (n&(n-1)) == 0;
12     }
原文地址:https://www.cnblogs.com/wzj4858/p/7701380.html