lc 231 Power of Two
Given an integer, write a function to determine if it is a power of two.
analysation##
Easy problem.
solution
bool isPowerOfTwo(int n) {
if (n <= 0)
return false;
while (n%2 == 0)
n = n>>1;
return (n == 1);
}
2024-01-05 16:27:22
Given an integer, write a function to determine if it is a power of two.
Easy problem.
bool isPowerOfTwo(int n) {
if (n <= 0)
return false;
while (n%2 == 0)
n = n>>1;
return (n == 1);
}