搜尋此網誌

2015年7月14日 星期二

Is Power of Two

public class IsPowerOfTwo {

 public boolean isPowerOfTwo(int n) {
  {
   while (((n % 2) == 0) && n > 1)
    /* While x is even and > 1 */
    n /= 2;
   return (n == 1);
  }
 }
}

沒有留言:

張貼留言