LeetCode Power of Two
来源:互联网 发布:精通python网络爬虫pdf 编辑:程序博客网 时间:2024/06/03 18:25
原题链接在这里:https://leetcode.com/problems/power-of-two/
思路:n一直除以2,直到1,若中间过程出现非偶数,就返回false。
Note: 1 也是power of two, 2的零次方。
AC Java:
public class Solution { public boolean isPowerOfTwo(int n) { if(n<1) return false; while(n!=1.0){ if((n%2) !=0) return false; n/=2; } return true; }}
0 0
- [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
- [LeetCode]Power of Two
- [leetcode] Power of two
- LeetCode Power of Two
- UVA 624 CD (DP)
- block详解
- HDU 1014 Uniform Generator
- ie自带打印
- UVA 10954
- LeetCode Power of Two
- 玩转Node.js - 03. 第一个I/O!
- hdu5358
- POJ 3268 Silver Cow Party(最短路dijkstra)
- Android屏幕适配全攻略(最权威的官方适配指导)
- 使用Unity3D的50个技巧:Unity3D最佳实践(下)
- 解决DM8168上电自动启动,不需要手动登陆root
- 基于 SurfaceView 详解 android 幸运大转盘,附带实例app
- 补丁比较工具Darun Grim使用