LeetCode 231:Power of Two
来源:互联网 发布:linux mesg 编辑:程序博客网 时间:2024/06/07 03:30
Given an integer, write a function to determine if it is a power of two.
给定一个数字,考虑它是否为2的幂
忘记考虑负数和0了。。。
class Solution {public: bool isPowerOfTwo(int n) { int sum=0; if(n<=0) return false; while(n!=0) { if(n&0x01==1) sum++; n>>=1; } if(sum==1) return true; return false; }};
0 0
- 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
- [Leetcode]#231 Power of Two
- Leetcode #231 Power of Two
- [LeetCode 231] Power of Two
- [leetcode 231]Power of Two
- 【LeetCode】231Power of Two
- 【LeetCode】231Power of Two
- LeetCode 231 Power of Two
- LeetCode 231:Power of Two
- git最细致的图文教程
- 【iOS】获取应用版本和语言
- os的组成
- 第12周项目5 迷宫问题之图深度优先遍历解法
- 在线微信编辑器(构思编辑器)——如何让微信公众号文章图文设计更完美
- LeetCode 231:Power of Two
- AsyncHttpClient
- 《Getting Real》书摘
- HDU 2571 路径权值最大 dp
- APS.NET MVC 过滤器
- dedecms 手机版与pc版分离方法分享
- Lucene的初次使用
- ECLIPSE崩溃启动不起来提示看log
- 使用cocos2dx编译到Android注意事项和NDK-build参数设置