leetcode [Power of Two]//待整理多种解法
来源:互联网 发布:辣鸭头淘宝配方 编辑:程序博客网 时间:2024/06/07 18:44
public class Solution { public boolean isPowerOfTwo(int n) { //采用暴力判断的方法,因为一个int最大是2^32-1,最小是-2^32,所以最多循环32次 //按题意,负数不算是2的幂 if(n < 0) return false; int temp = n;//先转化为绝对值 int count = 0;//计数 while(temp > 1){ count++; temp = temp / 2; } if(n == Math.pow(2, count)){//判断是否是2的幂 return true; } else{ return false; } }}
0 0
- leetcode [Power of Two]//待整理多种解法
- leetcode [Intersection of Two Linked Lists]//待整理多种解法
- leetcode[Minimum Index Sum of Two Lists]//待整理多种解法
- leetcode [Minimum Depth of Binary Tree]//待整理多种解法
- leetcode [Number of 1 Bits]//待整理多种解法
- leetcode[Sum of Left Leaves]//待整理多种解法
- leetcode[Diameter of Binary Tree]//待整理多种解法
- leetcode[Subtree of Another Tree]//待整理多种解法
- leetcode[Maximum Product of Three Numbers]//待整理多种解法
- leetcode [Path Sum]//待整理多种解法
- leetcode [Majority Element]//待整理多种解法
- leetcode [Rotate Array]//待整理多种解法
- leetcode [Reverse Bits]//待整理多种解法
- leetcode [Happy Number]//待整理多种解法
- leetcode [Isomorphic Strings]//待整理多种解法
- leetcode [Contains Duplicate]//待整理多种解法
- leetcode[Add Digits]//待整理多种解法
- leetcode[Ugly Number]//待整理多种解法
- Unity面试题170420
- 小心那些灾星
- 强大的矩阵奇异值分解(SVD)及其应用
- unity真机profiler调试
- 浅说深度学习(1):核心概念
- leetcode [Power of Two]//待整理多种解法
- 三四
- 找对象 ssl2637 费用流
- Splay 模版
- C#读取EXCEL 文件同时向文件中写入数据和Excel的Range对象
- 计算机视觉SIFT算法详解
- 组件方式开发 Web App全站-5-开发基本图文组件H5ComponentBase
- Molly's Chemicals CodeForces
- 【HTML+javaScript】滚动-跑马灯