231. power of two

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

题意分析:

通过计算可以知,当n = 30时,pow(2,n)为int型最大的数。

1
2
3
4
5
6
class Solution {
public:
bool (int n) {
return (n <= 0) ? false : ((int)pow(2,30) % n == 0);
}
};