LeetCode——Power of Two
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的更多相关文章
- [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 ...
- [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 ...
- [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 ...
- LeetCode Power of Four
原题链接在这里:https://leetcode.com/problems/power-of-four/ 题目: Given an integer (signed 32 bits), write a ...
- LeetCode Power of Three
原题链接在这里:https://leetcode.com/problems/power-of-three/ 与Power of Two类似.检查能否被3整除,然后整除,再重复检查结果. Time Co ...
- Leetcode Power of Two
Given an integer, write a function to determine if it is a power of two. 题目意思: 给定一个整数,判断是否是2的幂 解题思路: ...
- 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 ...
- 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 ...
- [LeetCode]Power of N
题目:Power of Two Given an integer, write a function to determine if it is a power of two. 题意:判断一个数是否是 ...
随机推荐
- [4G]Linux平台上实现4G通信
转自:http://blog.sina.com.cn/s/blog_7880d3350102wb92.html 在ARM平台上实现4G模块的PPP拨号上网,参考网上的资料和自己的理解,从一无所知到开发 ...
- Android——Button的颜色
.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android ...
- javascript 图片滚动
<div style="width:9999px;"> <ul id="marquePic1_1"> <li> <dl ...
- [Eclipse] 项目编码
一.修改eclipse的新建项目的编码 在菜单栏的 Window->Preferences->General->Workspace->Text file encoding 将其 ...
- 《FPGA全程进阶---实战演练》第三章之PCB设计之电感、磁珠和零欧姆电阻
2.电感.磁珠和零欧姆电阻的区别 电感:电感是储能元件,多用于电源滤波回路.LC振荡电路.中低频滤波电路等,其应用频率很少超过50MHz.对电感而言,其感抗值和频率成正比.XL = 2πfL来说明,其 ...
- e667. 在给定图像中创建缓冲图像
An Image object cannot be converted to a BufferedImage object. The closest equivalent is to create a ...
- goto 语句
goto 语句 自从提倡结构化设计以来,goto 就成了有争议的语句. 首先,由于 goto 语句可以 灵活跳转,如果不加限制,它的确会破坏结构化设计风格.其次,goto 语句经常带来错 误或隐患. ...
- ARP协议相关介绍
什么是ARP协议? ARP,即地址解析协议,实现通过IP地址得知其物理地址.在TCP/IP网络环境下,每个主机都分配了一个32位的IP地址,这种互联网地址是在网际范围标识主机的一种逻辑地址.为了让报文 ...
- 测试x264编码器的低延时编码和非延时编码
最近在学x264的编码,经过大量的测试,编码1080P的视频,编码10000帧数据. 在设置为低延时编码的时候: 编码线程0,一帧耗时:7.000000 ms.编码线程0,一帧耗时:8.000000 ...
- 【java 类加载的深入研究1】loadClass()的研究
1.开门见山 以前曾经看到过一个java的面试题,当时觉得此题很简单,可是自己把代码运行起来,可是结果并不是自己想象的那样.题目如下: class SingleTon { private static ...