【LeetCode】(231)Power of Two(Easy)
来源:互联网 发布:酷狗音乐数据异常 编辑:程序博客网 时间:2024/06/01 15:38
题目
Power of Two
Total Accepted: 21194 Total Submissions: 70828My SubmissionsGiven an integer, write a function to determine if it is a power of two.
解析
超级简单,每次判断是否能被2除,可以的话就除以2继续循环。考虑负数和1的情况。
class Solution {public: bool isPowerOfTwo(int n) { if (n == 1) { return true; } if (n <= 0) { return false; } while (n != 1) { if (n%2 != 0) { return false; } else { n = n/2; } } return true; }};
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
- 杭电2899Strange fuction 求导+二分
- hdoj 2112 HDU Today【3种方法】
- HDU 2149 Public Sale
- OWNCLOUD源码改动分析---登录模块
- ubuntu15.04安装chrome
- 【LeetCode】(231)Power of Two(Easy)
- Convert QWERTY to Dvorak (字符串)
- C++类所占空间总结
- 一个可以即插即用的MD5加密签名方式
- 字符串中的转义字符与字符串的长度
- 关于UIScreen的applicationFrame和bounds方法区别
- 输入n个整数,输出其中最小的k个
- CSU 1507 超大型LED显示屏
- log4j写日志到特定文件夹