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; } }
原文地址:https://www.cnblogs.com/wxisme/p/4623989.html