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的更多相关文章

  1. [LeetCode] Power of Four 判断4的次方数

    Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example: Gi ...

  2. [LeetCode] Power of Three 判断3的次方数

    Given an integer, write a function to determine if it is a power of three. Follow up:Could you do it ...

  3. [LeetCode] Power of Two 判断2的次方数

    Given an integer, write a function to determine if it is a power of two. Hint: Could you solve it in ...

  4. LeetCode Power of Four

    原题链接在这里:https://leetcode.com/problems/power-of-four/ 题目: Given an integer (signed 32 bits), write a ...

  5. LeetCode Power of Three

    原题链接在这里:https://leetcode.com/problems/power-of-three/ 与Power of Two类似.检查能否被3整除,然后整除,再重复检查结果. Time Co ...

  6. Leetcode Power of Two

    Given an integer, write a function to determine if it is a power of two. 题目意思: 给定一个整数,判断是否是2的幂 解题思路: ...

  7. Leetcode Power of two, three, four

    Given an integer, write a function to determine if it is a power of two. Hint: Could you solve it in ...

  8. leetcode power(x,n)

    class Solution { public: double pow(double x, int n) { double a=1; if(n==0)return 1; if(x==1)return ...

  9. [LeetCode]Power of N

    题目:Power of Two Given an integer, write a function to determine if it is a power of two. 题意:判断一个数是否是 ...

随机推荐

  1. jquery轮播控件

    网上找了一个轮播控件,效果不错,而且很容易改,需要的同学去下载咯 地址是:http://download.csdn.net/detail/jine515073/7704143

  2. js学习笔记16----父节点的操作

    1.元素.parentNode : 只读属性,获取当前元素的父节点. 2.元素.offsetParent : 只读属性,获取离当前元素最近的一个有定位属性(position为relative或者abs ...

  3. 用isNaN函数来判断是否只能输入正负数字

    isNaN() 函数通常用于检测 parseFloat() 和 parseInt() 的结果, 以判断它们表示的是否是合法的数字.当然也可以用 isNaN() 函数来检测算数错误,比如用 0 作除数的 ...

  4. Javascript 你不知道的事,好吧,是我不知道的事

    NaN表示一个不能产生正常结果的运算结果.它不等于任何值,包括它自己.可以用isNaN(number)来检测. 同Java中的字符串一样,JS中的字符串是不可变的.也就是说一旦字符串被创建,就无法改变 ...

  5. Spring IO platform 简介

    前提:熟悉Spring基础知识. 简介:Spring IO Platform将 the core Spring APIs 集成到一个Platform中.它提供了Spring portfolio中的大量 ...

  6. nodejs基础 -- 交互式解析器(REPL)

    ------------类似在浏览器中调试js代码----------------------- Node.js REPL(交互式解释器) Node.js REPL(Read Eval Print L ...

  7. linux -- at命令

    在windows系统中,windows提供了计划任务这一功能,在控制面板 -> 性能与维护 -> 任务计划, 它的功能就是安排自动运行的任务. 通过'添加任务计划'的一步步引导,则可建立一 ...

  8. ueditor1_4_3_3编辑器修改文章

    html的body中: <script id="editor" type="text/plain" ></script> js中: // ...

  9. cesium图形上加载图片

    <!DOCTYPE html> <html> <head> <!-- Use correct character set. --> <meta c ...

  10. 手机web不同屏幕字体大小高度自适应

    body{font-size:0.6rem:} <script> //使用rem策略,不断更新html的fontsize (function(){     function sizeHtm ...