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

 

 1 class Solution {
 2 public:
 3     bool isPowerOfTwo(int n) {
 4         if(n <= 0){
 5             return false;
 6         }
 7         
 8         return (n&(n-1)) == 0 ;
 9     }
10 };

 

相关文章: