首页 > 其他 > 详细

Leetcode 231: Power of Two

时间:2017-12-03 12:40:08      阅读:232      评论:0      收藏:0      [点我收藏+]

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

 

 1 public class Solution {
 2     public bool IsPowerOfTwo(int n) {
 3         if (n <= 0) return false;
 4         if (n <= 2) return true;
 5         
 6         while (n > 2)
 7         {
 8             if (n % 2 != 0) return false;
 9             n = n / 2;
10         }
11         
12         return true;
13     }
14 }

 

Leetcode 231: Power of Two

原文:http://www.cnblogs.com/liangmou/p/7965674.html

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