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; } }
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; } }
本站原创文章皆遵循“署名-非商业性使用-相同方式共享 3.0 (CC BY-NC-SA 3.0)”。转载请保留以下标注:
原文来源:《231. Power of Two》