leetcode刷题日记——Power of Two
来源:互联网 发布:沈阳网络优化11sem 编辑:程序博客网 时间:2024/06/01 17:49
Given an integer, write a function to determine if it is a power of two.
问题分析:题目目标明显,判断一个数是否为2的指数幂。首先如果一个数不能被2整除,肯定排除。另外能整除的数中又分为,最终一直除以2之后,中途不终止的倒最变成一的肯定是,具体实现代码如下:
class Solution {public: bool isPowerOfTwo(int n) { if(n==1) return true; else{ while(n>1){ if(n%2!=0) return false; else n/=2; } if(n==1) return true; else return false; } }};
0 0
- leetcode刷题日记——Power of Two
- Leetcode——231. Power of Two
- LeetCode每日一题——231. Power of Two
- [LeetCode] Power of Two
- 【LeetCode】Power of Two
- [Leetcode]Power of Two
- [leetCode] Power of Two
- leetcode --Power of Two
- leetcode: Power of Two
- LeetCode Power of Two
- [LeetCode] Power of Two
- LeetCode Power of Two
- [leetcode] Power of Two
- [Leetcode]Power of Two
- Leetcode: Power of Two
- [LeetCode]Power of Two
- leetcode | Power of Two
- 【leetcode】Power of Two
- 函数模板与类模板的简单实例
- java文件下载的文件名乱码问题的解决
- ubuntu14.04(linux)字符界面下openfire安装配置
- 归并排序(Mergesort)
- 《Effective java》读书记录-第3条-用私有构造器或者枚举类型强化Singleton属性
- leetcode刷题日记——Power of Two
- oracle 反向排序
- oc基础总结二 线程和进程
- 欢迎使用CSDN-markdown编辑器
- MP4文件格式详解——结构概述
- Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for pr
- Home+work
- asp.net dataset 判断是否为空
- 【ASUS】win7下安装USB3.0驱动蓝屏死机问题