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. java的static块执行时机<转>

    一.误区:简单认为JAVA静态代码块在类被加载时就会自动执行.证错如下: class MyClass1 { static {//静态块 System.out.println("static  ...

  2. Fiddler2 java代码拦截设置

    jre -DproxySet=true -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=8888 Or: jre -DproxySet=true -Dproxy ...

  3. iOS边练边学--通知机制和键盘处理

    一.通知中心(NSNotificationCenter) 每一个程序都有一个通知中心实例,专门负责协助不同对象之间的消息通信 任何一个对象都可以想通知中心发布通知(NSNotification),描述 ...

  4. Entity Framework应用:使用LINQ操作

    一.什么是LINQ TO EntitiesLINQ,全称是Language-INtegrated Query(集成语言查询),是.NET语言中查询数据的一种技术.LINQ to Entities是一种 ...

  5. Java打印整数的二进制表示(代码与解析)

    Java打印整数的二进制表示(代码与解析) int a=-99; for(int i=0;i<32;i++){ int t=(a & 0x80000000>>>i)&g ...

  6. 无法从“重载函数类型”为“const std::_Tree<_Traits> &”推导 <未知> 参数

    场景: 原因: 用到string类型,但是没有包含头文件. 解决方法: #include<string>

  7. linux -- 服务开机自启动

    好吧,最近需要用到开机启动服务,百度了一下,几乎都是一个版本,然后之间各种传递.我也抄个 ******************************************************* ...

  8. API Design Principles -- QT Project

    [the original link] One of Qt’s most reputed merits is its consistent, easy-to-learn, powerfulAPI. T ...

  9. 【Java面试题】27 多线程笔试面试概念问答

    第一题:线程的基本概念.线程的基本状态及状态之间的关系? 线程,有时称为轻量级进程,是CPU使用的基本单元:它由线程ID.程序计数器.寄存器集合和堆栈组成.它与属于同一进程的其他线程共享其代码段.数据 ...

  10. informatica 中的workflow连接mysql数据配置DSN

    先要下载mysqlodbc 一步步安装之后 ,再从管理工具里面找到ODBC,最后选择系统DSN,添加mysql驱动之后,进入添加编辑: 在workflow里面的配置连接字符串就写刚刚配置的连接名称 比 ...