问题描述:

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

问题分析:给定一个数,判断它是不是2的幂。因为2的幂 >= 0 ,所以是针对非负数的。那么这个数 %2为0

代码:

public boolean isPowerOfTwo(int n) {
if(n <= 0)
return false;
while(n % 2 == 0 )
n = n / 2; //不断地除以2
if(n == 1)
return true;
else
return false;
}

Power Of Two leetcode java的更多相关文章

  1. N-Queens II leetcode java

    题目: Follow up for N-Queens problem. Now, instead outputting board configurations, return the total n ...

  2. LeetCode算法题-Power of Four(Java实现-六种解法)

    这是悦乐书的第205次更新,第216篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第72题(顺位题号是342).给定一个整数(带符号的32位),写一个函数来检查它是否为4 ...

  3. LeetCode算法题-Power Of Three(Java实现-七种解法)

    这是悦乐书的第204次更新,第215篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第71题(顺位题号是326).给定一个整数,写一个函数来确定它是否为3的幂.例如: 输入 ...

  4. LeetCode算法题-Power Of Two(Java实现)

    这是悦乐书的第194次更新,第200篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第56题(顺位题号是231).给定一个整数,写一个函数来确定它是否是2的幂.例如: 输入 ...

  5. Regular Expression Matching leetcode java

    题目: Implement regular expression matching with support for '.' and '*'. '.' Matches any single chara ...

  6. Sqrt(int x) leetcode java

    Reference: http://blog.csdn.net/lbyxiafei/article/details/9375735  题目: Implement int sqrt(int x). Co ...

  7. ZigZag Conversion leetcode java

    题目: The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows l ...

  8. [LeetCode][Java]Candy@LeetCode

    Candy There are N children standing in a line. Each child is assigned a rating value. You are giving ...

  9. [Leetcode][JAVA] Valid Palindrome

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

随机推荐

  1. NodeJs 在window中安装使用

    Nodejs: 官网下载长期版本zip格式解压 D:\Program Files\nodejs 查看版本 D:\Git\SpringBootDemo (master) $ node -v v8.11. ...

  2. CodeForces 459C Pashmak and Buses(构造)题解

    题意:n个人,k辆车,要求d天内任意两人都不能一直在同一辆车,能做到给出构造,不能输出-1 思路:我们把某一个人这d天的车号看成一个d位的数字,比如 1 1 2 3代表第一天1号车.第二天1号车.第三 ...

  3. 【htop】Linux CentOS 6.5下安装htop进程管理工具

    一.Htop的使用简介 This is htop, an interactive process viewer for Linux. It is a text-mode application (fo ...

  4. [CodeForces - 276A] Lunch Rush

    题目链接:http://codeforces.com/problemset/problem/276/A 从这n个输入中求最大值,注意 和 k的比较,定义一个maxn,对每个输入进行计算即可. AC代码 ...

  5. facebook api之Business Manager API

    Business-scoped Users - The new user is tied to a particular business and has permissions scoped to ...

  6. Linux安装svn客户端

    Red Hat Linux 1.安装$ yum install subversion 2.常见问题1.执行svn报错:cannot set LC_CTYPE localevi /etc/profile ...

  7. POJ 3087 Shuffle'm Up(洗牌)

    POJ 3087 Shuffle'm Up(洗牌) Time Limit: 1000MS    Memory Limit: 65536K Description - 题目描述 A common pas ...

  8. 如何某个js文件中的 console

    因为自己引用了别人的一个 js 文件,但里面有很多事件相关的 console 输出.自己并不想去修改别人的文件.但想屏蔽掉里面的 console . 有多个 js 文件里有 console.log . ...

  9. FB01与F-02的区别(转载)

    FB01与F-02的区别(转载) FB01 : a) ''Post Document'' b) No doc type as SA automatically comes. c) No automat ...

  10. SAP FI CO模块常用事务代码

                                                                                                        ...