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. 题意:判断一个数是否是 ...
随机推荐
- [shell]shell脚本传入不固定参数的写法,如--help等
最近在调试一个wifi模块,需要传一些不固定的参数,一下一个参数解析的函数可以搞定这个事情,里面内容好多部分是从一个example中剽窃而来(窃喜) #!/bin/bash # writen by a ...
- Android——控件AutoCompleteTextView 自动提示
Android:控件AutoCompleteTextView 自动提示 在输入框中输入我们想要输入的信息就会出现其他与其相关的提示信息,这种效果在Android中是用AutoCompleteTextV ...
- CMake使用入门
一.开胃菜 hello目录下的文件结构: ├── CMakeLists.txt ├── hello.c ├── hello.h └── main.c C代码见下节. 最简单的cmake配置文件: pr ...
- phalcon的CLI应用
CLI应用是命令行下执行的程序, 可以应用于定时任务,守护进程, 脚本, 公用命令等等. 最小的目录结构:app/config/config.phpapp/tasks/MainTask.phpapp/ ...
- Hibernate-HQL&QBC基础使用(分页)
@Test public void testHql() { Configuration configuration = new Configuration().configure(); Session ...
- CentOS每次开机都要ifup eth0的解决方法小结
vim /etc/sysconfig/network-scripts/ifcfg-eth0 把里面的 ONBOOT 设为 yes 即可. [编辑]艺搜参考 http://www.jbxue.com/L ...
- 专题实验 Statspack & 9大动态视图
statspack 是一个DBA经常用的调优工具, 它的主要作用是, 针对数据库的不同时刻做快照, 然后来比对快照之前的差异和瓶颈, 快照可以是手动的也可以是自动的, 从 oracle 10g开始, ...
- android activity lifecycle
学习android的activity,之前一直没有去琢磨,今天正好了解一下activity生命周期. 参考链接: https://developer.android.com/guide/compone ...
- centos7命令总结
1,查看cpu信息 lscpu 2,网络配置 ip route 查看路由 nmcli nmcli connection show 显示所有连接 nmcli connection show ...
- 【Java面试题】17 如何把一个逗号分隔的字符串转换为数组? 关于String类中split方法的使用,超级详细!!!
split 方法:将一个字符串分割为子字符串,然后将结果作为字符串数组返回. stringObj.split([separator],[limit])参数:stringObj 必选项.要被分解的 ...