LeetCode之旅(19)-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.
思路
判断一个整数,是不是的2的次方数 ,利用对2求余,来循环除以2,看最后是不是1
代码:
public class Solution {
public boolean isPowerOfTwo(int n) {
if(n <= 0){
return false;
}else{
while(n % 2 == 0){
n = n/2;
}
return n == 1;
}
}
}
LeetCode之旅(19)-Power of Two的更多相关文章
- leetcode之旅(11)-Integer to Roman
题目描述: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range fr ...
- LeetCode之旅(13)-Valid Anagram
题目介绍: Given two strings s and t, write a function to determine if t is an anagram of s. For example, ...
- LeetCode 第 231 题 (Power of Two)
LeetCode 第 231 题 (Power of Two) Given an integer, write a function to determine if it is a power of ...
- LeetCode之旅(20)-Power of Three
题目: Given an integer, write a function to determine if it is a power of three. Follow up: Could you ...
- LeetCode - 326, 342, 231 Power of Three, Four, and Two
1. 问题 231. Power of Two: 判断一个整数是否是2的n次方,其中n是非负整数 342. Power of Four: 判断一个整数是否是4的n次方,其中n是非负整数 326. Po ...
- LeetCode 第 342 题(Power of Four)
LeetCode 第 342 题(Power of Four) Given an integer (signed 32 bits), write a function to check whether ...
- <LeetCode OJ> 326. Power of Three
326. Power of Three Question Total Accepted: 1159 Total Submissions: 3275 Difficulty: Easy 推断给定整数是否是 ...
- 【LeetCode】869. Reordered Power of 2 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典统计每位数字出现的次数 日期 题目地址:http ...
- .NET平台开源项目速览(19)Power BI神器DAX Studio
PowerBI更新频繁,已经有点更不上的节奏,一直在关注和学习中,基本的一些操作大概是没问题,更重要的是注重Power Query,M函数,以及DAX的使用,这才是核心. 上个月研究了DAX的一些 ...
随机推荐
- FORM的静态提交
在form中进行保存时,如果使用commit_form的话会弹出信息提示"没有修改需要保存"或者"几条记录已保存"类似的字样,有时候不想被提示,可以使用A ...
- 使用Broadcast实现android组件之间的通信
android组件之间的通信有多种实现方式,Broadcast就是其中一种.在activity和fragment之间的通信,broadcast用的更多本文以一个activity为例. 效果如图: 布局 ...
- 深入剖析Tomcat会话机制
1缓存机制 Tomcat默认将Session保存到内存中.但同时,Tomcat也提供了PersistentManager配合不同的Store实现的方式,使Session可以被保存到不同地方(Datab ...
- 快速高分辨率图像的立体匹配方法Effective large scale stereo matching
<Effective large scale stereo matching> In this paper we propose a novel approach to binocular ...
- svn 回退/更新/取消至某个版本命令详解
1. 取消Add/Delete 取消文件 svn revert 文件名 取消目录 svn revert --depth=infinity 目录名 2. 回退版本 方法1: 用svn merge 1) ...
- iOS中 Swift初级入门学习(三)
// // main.swift // LessonSwift-03 // // Copyright (c) 2015年 韩俊强. All rights reserved. // import Fou ...
- SQL Server性能优化与管理的艺术 附件下载地址
首先感谢读者们对鄙人的支持,购买了<SQL Server性能优化与管理的艺术>,由于之前出版社的一些疏忽,附件没有上传成功,再次本人深表歉意. 请需要下载附件的读者从下面链接下载,谢谢: ...
- 1022. Digital Library (30) -map -字符串处理
题目如下: A Digital Library contains millions of books, stored according to their titles, authors, key w ...
- iOS编程中的音频知识(二):那么多种格式我应该用哪一个?
iPhone支持不少格式,比如AAC,HE-AAC,AMR,IMA4等等,你可以在以下网址看到比较全的格式和简要介绍: http://www.raywenderlich.com/69365/audio ...
- JDK6和JDK7中String的substring()方法及其差异
翻译人员: 铁锚 翻译日期: 2013年11月2日 原文链接: The substring() Method in JDK 6 and JDK 7 在JDK6与JDK7这两个版本中,substri ...