【菜鸟的leetcode之旅】231.power of two
来源:互联网 发布:win7下nginx配置php 编辑:程序博客网 时间:2024/05/25 05:36
【问题描述】简单的说就是求2的幂,这个用到的解题思路是利用了二进制的2的幂的特点。关于2的幂,都是1,10,100,1000...观察可以知道其首位是1,其它都为0.我们可以利用并运算,对二进制进行运算。其核心算法是n&(n-1)==0
bool isPowerOfTwo(int n) { if(n<=0) return false; return ((n&(n-1))==0);}============================//求4的幂 bool isPowerOfFour(int num) { if(num<=0) return false; return ((num&(num-1))==0 && num&0x55555555);}
阅读全文
0 0
- 【菜鸟的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] 231.Power of Two
- LeetCode ||231. Power of Two
- [LeetCode]231.Power of Two
- Leetcode 231. Power of Two
- leetcode 231. Power of Two
- 231. Power of Two LeetCode
- [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
- 使用idea 搭建ssm+maven+logback项目
- 给ESXi虚拟机硬盘瘦身
- 给定一个整数N,那么N的阶乘N!末尾有多少个0
- C++复习第四天 函数重载
- HashMap底层实现原理及面试问题
- 【菜鸟的leetcode之旅】231.power of two
- RTMPdump(libRTMP) 源代码分析 10: 处理各种消息(Message)
- 使用Django的认证(authentication)
- 计算一个整数二进制位中1的个数
- 排序算法
- Linux 忘记mysql root 密码 修改mysql 的root权限和密码
- 使用LVS实现负载均衡原理及安装配置详解
- js中变量和jsp中java代码中变量互相访问解决方案
- oracle之DQL,DML以及常用函数(重点)