public boolean isPowerOfTwo(int n) {
if(n<1)
return false;
while(n!=1){
if(n%2!=0)
return false;
n>>=1;
}
return true;
}

Java for LeetCode 231 Power of Two的更多相关文章

  1. [LeetCode] 231 Power of Two && 326 Power of Three && 342 Power of Four

    这三道题目都是一个意思,就是判断一个数是否为2/3/4的幂,这几道题里面有通用的方法,也有各自的方法,我会分别讨论讨论. 原题地址:231 Power of Two:https://leetcode. ...

  2. [LeetCode] 231. Power of Two 2的次方数

    Given an integer, write a function to determine if it is a power of two. Example 1: Input: 1 Output: ...

  3. LN : leetcode 231 Power of Two

    lc 231 Power of Two 231 Power of Two Given an integer, write a function to determine if it is a powe ...

  4. Java [Leetcode 231]Power of Two

    题目描述: Given an integer, write a function to determine if it is a power of two. 解题思路: 判断方法主要依据2的N次幂的特 ...

  5. LeetCode 231 Power of Two

    Problem: Given an integer, write a function to determine if it is a power of two. Summary: 判断一个数n是不是 ...

  6. Leetcode 231 Power of Two 数论

    同样是判断数是否是2的n次幂,同 Power of three class Solution { public: bool isPowerOfTwo(int n) { ) && ((( ...

  7. (easy)LeetCode 231.Power of Two

    Given an integer, write a function to determine if it is a power of two. Credits:Special thanks to @ ...

  8. [LeetCode] 231. Power of Two ☆(是否2 的幂)

    描述 Given an integer, write a function to determine if it is a power of two. 给定一个整数,编写一个函数来判断它是否是 2 的 ...

  9. LeetCode - 231. Power of Two - 判断一个数是否2的n次幂 - 位运算应用实例 - ( C++ )

    1.题目:原题链接 Given an integer, write a function to determine if it is a power of two. 给定一个整数,判断该整数是否是2的 ...

随机推荐

  1. 快速切换IP的批处理!

    内容如下: @echo off color 1A Title [SMART专用 IP设置V1.0] cls echo. echo SMART专用 IP设置V1.0 %date%%time% echo. ...

  2. poj3335 半交平面,多边形内核

    Rotating Scoreboard Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5300   Accepted: 21 ...

  3. zstu.2512. Moving Tables(贪心)

     Moving Tables Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 1182  Solved: 563 Description The famo ...

  4. 【python网络编程】使用rsa加密算法模块模拟登录新浪微博

    一.基础知识 http://blog.csdn.net/pi9nc/article/details/9734437 二.模拟登录 因为上学期参加了一个大数据比赛,需要抓取数据,所以就想着写个爬虫抓取新 ...

  5. redis--key1

    package com.ztest.redis; import java.util.Set; import com.sun.istack.internal.logging.Logger; import ...

  6. compareTo(String str)与compareToIgnoreCase(String str)

    一.compareTo(String str)方法 返回值:如果参数字符串等于此字符串,则返回值 0:如果此字符串按字典顺序小于字符串参数,则返回一个小于 0 的值:如果此字符串按字典顺序大于字符串参 ...

  7. 2016年10月16日--ArrayList集合、特殊集合

    ArrayList集合 使用前引用 using System.Collections; ArrayList集合 实例化.初始化 ArrayList al = new ArrayList(); Arra ...

  8. 网页嵌入swf代码

    <object class id="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://dow ...

  9. PyQt4软件打包成exe文件

    使用py2exe进行打包 例: from distutils.core import setupimport py2exeimport sys sys.argv.append('py2exe') py ...

  10. nginx 免安装包

    在一个环境下编译安装好nginx,然后可以拷贝到其他环境使用.同时避免直接安装造成的环境冲突. 首先下载好nginx和相关插件.然后编译安装到沙盒里面.demo如下: cd到nginx目录 ./con ...