leetcode/231.c
2024-09-08 14:39:20 +08:00

27 lines
390 B
C

//
// Created by aurora on 24-8-14.
//
#include <assert.h>
#include <stdbool.h>
bool isPowerOfTwo(int n)
{
if (n <= 0)
return false;
while (n / 2)
{
if (n % 2 != 0)
return false;
n /= 2;
}
return true;
}
int main()
{
assert(isPowerOfTwo(2) == true);
assert(isPowerOfTwo(0) == false);
assert(isPowerOfTwo(1) == true);
}