`
hcx2013
  • 浏览: 82130 次
社区版块
存档分类
最新评论

Power of Two

 
阅读更多

Given an integer, write a function to determine if it is a power of two.

 

public class Solution {
    public boolean isPowerOfTwo(int n) {
        if (n == 0) {
        	return false;
        }
        while (n % 2 == 0) {
        	n /= 2;
        }
        return n == 1 ? true : false;
    }
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics