LeetCode OJ:Power of Two(2的幂)
Given an integer, write a function to determine if it is a power of two.
看一个数是不是2的幂,代码如下:
class Solution {
public:
bool isPowerOfTwo(int n) {
if(n<=) return false;
bool isPower = false;
for(int i = ; i < n; i<<=){
if(!isPower && (i&n))
isPower = true;
else if(isPower && (i&n)){
return false;
}
}
return true;
}
};
LeetCode OJ:Power of Two(2的幂)的更多相关文章
- LeetCode OJ:Pow(x, n) (幂运算)
Implement pow(x, n). 幂运算,简单的方法snag然很好实现,直接循环相乘就可以了,但是这里应该不是那种那么简单,我的做法使用到了一点递归: class Solution { pub ...
- LeetCode OJ 题解
博客搬至blog.csgrandeur.com,cnblogs不再更新. 新的题解会更新在新博客:http://blog.csgrandeur.com/2014/01/15/LeetCode-OJ-S ...
- leetcode 326. Power of Three(不用循环或递归)
leetcode 326. Power of Three(不用循环或递归) Given an integer, write a function to determine if it is a pow ...
- 【LeetCode OJ】Interleaving String
Problem Link: http://oj.leetcode.com/problems/interleaving-string/ Given s1, s2, s3, find whether s3 ...
- 【LeetCode OJ】Reverse Words in a String
Problem link: http://oj.leetcode.com/problems/reverse-words-in-a-string/ Given an input string, reve ...
- LeetCode OJ学习
一直没有系统地学习过算法,不过算法确实是需要系统学习的.大二上学期,在导师的建议下开始学习数据结构,零零散散的一学期,有了链表.栈.队列.树.图等的概念.又看了下那几个经典的算法——贪心算法.分治算法 ...
- LeetCode OJ 297. Serialize and Deserialize Binary Tree
Serialization is the process of converting a data structure or object into a sequence of bits so tha ...
- 备份LeetCode OJ自己编写的代码
常泡LC的朋友知道LC是不提供代码打包下载的,不像一般的OJ,可是我不备份代码就感觉不舒服- 其实我想说的是- 我自己写了抓取个人提交代码的小工具,放在GitCafe上了- 不知道大家有没有兴趣 ht ...
- LeetCode OJ 之 Maximal Square (最大的正方形)
题目: Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ...
- LeetCode OJ:Integer to Roman(转换整数到罗马字符)
Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...
随机推荐
- Hive环境安装
说明: (Hbase依赖于Hadoop,同时需要把元数据存放在mysql中),mysql自行安装 Hadoop2.0安装参考我的博客: https://www.cnblogs.com/654wangz ...
- servlet中通过getWriter()获取out返回给浏览器出现中文乱码问题
感谢博主https://blog.csdn.net/louyongfeng3613/article/details/50160317 在Servlet编程中,经常需要通过response对象将一些信息 ...
- Android系统init进程启动及init.rc全解析
转:https://blog.csdn.net/zhonglunshun/article/details/78615980 服务启动机制system/core/init/init.c文件main函数中 ...
- Java哲学家进餐
某次操作系统实验存档. 这个哲学家除了吃就是睡.. 哲学家.java: package operating.entity.philosophyeating; import operating.meth ...
- 第三方CSS安全吗?
原文:https://jakearchibald.com/201...翻译:疯狂的技术宅 本文首发微信公众号:jingchengyideng欢迎关注,每天都给你推送新鲜的前端技术文章 前一段时间,有很 ...
- 20145303刘俊谦 《Java程序设计》实验四 实验报告
实验要求 完成实验.撰写实验报告,实验报告以博客方式发表在博客园,注意实验报告重点是运行结果,遇到的问题(工具查找,安装,使用,程序的编辑,调试,运行等).解决办法(空洞的方法如"查网络&q ...
- 20145331 《Java程序设计》第8周学习总结
20145331 <Java程序设计>第8周学习总结 教材学习内容总结 14.NIO与NIO2 高级的输入输出处理,可以使用NIO(New IO),NIO2是文件系统的API Channe ...
- 20135320赵瀚青LINUX第五周学习笔记
赵瀚青原创作品转载请注明出处<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 概述 按照刘老师的周从三个角 ...
- python爬虫之新浪微博登录
fiddler 之前了解了一些常见到的反爬措施,JS加密算是比较困难,而微博的登录中正是用JS加密来反爬,今天来了解一下. 分析过程 首先我们去抓包,从登录到微博首页加载出来的过程.我们重点关注一下登 ...
- Nginx配置X-Forwarded-Proto
需求 最近公司在做全站https,架构上面有Nginx+tomcat Nginx+php,且nginx配置了ssl,tomcat和php项目使用https协议 但是,发送的是https url请求,p ...