首页 > 其他 > 详细

Power of Two

时间:2015-08-06 12:29:46      阅读:172      评论:0      收藏:0      [点我收藏+]

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.

Power of Two

原文:http://www.cnblogs.com/catcoding/p/4707298.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!