公式法;sizeof(bool[n][n+1])等价于n(n+1)
class Solution {
public:
int sumNums(int n) {
return sizeof(bool[n][n+1])>>1;
}
};
class Solution {
public:
bool isPowerOfFour(int n) {
if(n<=0) return false;
int x=(int)(log2(n)/log2(4));
if(n-pow(4,x)==0) return true;
return
false;
};
3次幂同理
-
class Solution {
-
public:
-
bool isPowerOfThree(int n) {
-
if(n<=0) return false;
-
int x=(int)(log2(n)/log2(3));
-
if(n-pow(3,x)==0) return true;
-
return false;
-
}
-
};