231. Power of Two
2016-09-09 本文已影响0人
a_void
Given an integer, write a function to determine if it is a power of two.
class Solution {
public:
bool isPowerOfTwo(int n) {
return n < 1 ? false : (n | (n-1)) == n * 2 - 1;
}
};
Given an integer, write a function to determine if it is a power of two.
class Solution {
public:
bool isPowerOfTwo(int n) {
return n < 1 ? false : (n | (n-1)) == n * 2 - 1;
}
};