Given an integer, write a function to determine if it is a power of two.
class Solution {
public boolean isPowerOfTwo(int n) {
if(n == 0) return false;
while(n%2 == 0){
n = n/2;
}
return n==1;
}
}
This site Original article All followed" Attribution—NonCommercial—ShareAlike 4.0 (CC BY-NC-SA 4.0) ”。 Please keep the following marks for sharing and interpretation:
Original author: Jake Tao Source: 「231. Power of Two」
Post a reply