LeetCode——Power of Two

Description:

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





public class Solution { public boolean isPowerOfTwo(int n) { boolean flag = false; if(n == 0) return false; while(true) { if(n == 1) { flag = true; break; } if(n % 2 != 0) { flag = false; break; } else { n /= 2; } } return flag; } }

 

posted @ 2015-07-06 11:45  Pickle  阅读(200)  评论(0编辑  收藏  举报