Power of Two

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

判断一个integer是否为2的幂。

 1 public class Solution {
 2     public static boolean isPowerOfTwo(int n) {
 3           double d = n;
 4           
 5           if(d==1){
 6               return true;
 7           }
 8             while(d>=2){
 9                 d = d/2;
10                 if(d==1){
11                     return true;
12                 }
13             }
14             return false;
15         }
16 }

252 ms.

原文地址:https://www.cnblogs.com/catcoding/p/4707298.html