231. Power of Two

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 };

 

posted on 2016-09-12 10:26  三颗心  阅读(102)  评论(0编辑  收藏  举报

导航