LeetCode #231 - Power of Two - Easy
来源:互联网 发布:mysql数据库设计 编辑:程序博客网 时间:2024/05/29 13:15
Problem
Given an integer, write a function to determine if it is a power of two.
Example
Input: 2Output: true
Algorithm
整理一下题意:给定一个整数,判断其是否是2的幂。
简单判断即可。注意特殊情况,如负数,0,1。
代码如下。
class Solution {public: bool isPowerOfTwo(int n) { if(n<=0) return false; bool isp=true; while(n){ if(n%2==1&&n!=1){ isp=false; break; } n/=2; } return isp; }};
0 0
- [Leetcode 231, Easy] Power of Two
- 【LeetCode】(231)Power of Two(Easy)
- <LeetCode><Easy>231 Power of Two
- LeetCode #231 - Power of Two - Easy
- 【leetcode】Power Of Two[easy]
- leetcode 231 Power of Two(难易度:Easy)
- LeetCode 231. Power of Two --Easy
- Leetcode 231. Power of Two (Easy) (cpp)
- leetcode-231 Power of Two
- leetcode 231:Power of Two
- LeetCode 231: Power of Two
- leetcode 231: Power of Two
- leetcode[231]:Power of Two
- Power of Two(leetcode 231)
- leetcode-231-Power of Two
- LeetCode 231 Power of Two
- leetCode #231 Power of Two
- leetcode 231: Power of Two
- ZCMU—1774
- pm2 管理nodejs 日志存放问题
- Oracle materizlized view Study
- 关于dispose 方法的资源释放
- 多线程中的Join()方法
- LeetCode #231 - Power of Two - Easy
- 架构设计的原则
- UML关系和图解析
- Apache与Nginx的优缺点比较
- error: could not install *smartsocket* listener: cannot bind to 127.0.0.1:5037: 通常每个套接字地址。。。
- 知识库--Pipelining Tasks
- AsyncTask的缺陷和问题
- TCP协议与UDP协议的区别
- 程序员修炼之道 读书笔记