码迷,mamicode.com
首页 > 其他好文 > 详细

LeetCode——Power of Two

时间:2015-07-06 13:58:57      阅读:84      评论:0      收藏:0      [点我收藏+]

标签:

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; } }

 

LeetCode——Power of Two

标签:

原文地址:http://www.cnblogs.com/wxisme/p/4623989.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!