[231]Power of Two
来源:互联网 发布:什么是淘宝客返利网 编辑:程序博客网 时间:2024/05/17 00:51
【题目描述】
Given an integer, write a function to determine if it is a power of two.
【思路】
将n循环除以2,一旦出现余数不为0的情况即为false,注意有两个数0和1为特殊情况要加以判断.
【代码】
class Solution {public: bool isPowerOfTwo(int n) { if(n==0) return false; if(n==1) return true; while(n!=1){ if(n%2!=0) return false; n=n/2; } return true; }};
0 0
- 231Power of Two
- 231 Power of Two
- 231Power of Two
- 231 - power of two
- 231Power of Two
- 231 Power of Two
- 231:Power of Two
- [231]Power of Two
- 231 Power of Two
- Power of Two---231
- [231] Power of Two
- leetcode-231 Power of Two
- leetcode 231:Power of Two
- LeetCode 231: Power of Two
- 231-e-Power of Two
- leetcode 231: Power of Two
- leetcode[231]:Power of Two
- Power of Two(leetcode 231)
- 一起学spring--我的第一个Spring程序,简单粗暴易懂
- POJ 3902 The Bad Number(贪心)
- Linux写时拷贝技术(copy-on-write)
- 聊天界面,frame模型
- DirectX11 创建混合状态
- [231]Power of Two
- 【UML】对象图Object diagram
- 解释性语言和编译性语言的区别
- 剑指offer—二叉搜索树与双向链表
- UI-视频知识点总结
- META
- 学习ThinkPHP3.2.2:video11,Index类中一行代码查询表、由指定模板输出内容
- 简单问题窥见数学
- StoryBoard