231. Power of Two
- Total Accepted: 109740
- Total Submissions: 281506
- Difficulty: Easy
- Contributors: Admin
Given an integer, write a function to determine if it is a power of two.
Credits:
Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.
It's too easy to explain......
bool isPowerOfTwo(int n) {
while(n > 1){
if(n%2 == 0){
n = n/2;
}else{
break;
}
}
return n == 1;
}