231Power of Two
来源:互联网 发布:哪里能找到工资数据 编辑:程序博客网 时间:2024/04/30 14:16
231 Power of Two
链接:https://leetcode.com/problems/power-of-two/
问题描述:
Given an integer, write a function to determine if it is a power of two.
Credits:
Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.
Hide Tags Math Bit Manipulation
求一个数字是不是2的幂。如果一个数字是2的幂那么在二进制标识中,一定有且仅有一个1。
class Solution {public: bool isPowerOfTwo(int n) { int sum=0; if(n<0) return false; for(int i=0;i<32;i++) { sum+=(n&1); n>>=1; } if(sum==1) return true; else return false; }};
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)
- Linux运维基础采集项
- EditText 动态切换密码 更改为"*"
- 大型网站架构演变和知识体系
- [学习笔记—Objective-C]《Objective-C 程序设计 第6版》第十二章 预处理程序
- 如何修改eclipse 中Android的预览layout布局背景颜色
- 231Power of Two
- Android学习——在线查看android源代码的3种方式
- Android studio 获取 sh1和MD5
- angular 第一章 helloword
- [uWSGI] Python threading and locks
- typcqurlauimig
- PS色调— —通道混合
- hadoop一些基本知识——Mapreduce 整个工作机制图
- 大地测量系统与参考框架