LeetCode 第 231 题 (Power of Two)
LeetCode 第 231 题 (Power of Two)
Given an integer, write a function to determine if it is a power of two.
这个题目有个特别简单的解法。当然。可以独自想出这种方法可不简单。这样的方法可以作为一个知识点记住就好了。
class Solution {
public:
bool isPowerOfTwo(int n) {
if(n <= 0) return false;
return !(n & (n - 1));
}
};
LeetCode 第 231 题 (Power of Two)的更多相关文章
- LeetCode 第 342 题(Power of Four)
LeetCode 第 342 题(Power of Four) Given an integer (signed 32 bits), write a function to check whether ...
- LeetCode 第 342 题(Power of Four)
LeetCode 第 342 题(Power of Four) Given an integer (signed 32 bits), write a function to check whether ...
- 【JavaScript】Leetcode每日一题-平方数之和
[JavaScript]Leetcode每日一题-平方数之和 [题目描述] 给定一个非负整数 c ,你要判断是否存在两个整数 a 和 b,使得 a2 + b2 = c . 示例1: 输入:c = 5 ...
- 【python】Leetcode每日一题-矩阵置零
[python]Leetcode每日一题-矩阵置零 [题目描述] 给定一个 m x n 的矩阵,如果一个元素为 0 ,则将其所在行和列的所有元素都设为 0 .请使用 原地 算法. 进阶: 一个直观的解 ...
- leetcode 第188题,我的解法,Best Time to Buy and Sell Stock IV
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255) ...
- leetcode第37题--Count and Say
题目:(据说是facebook的面试题哦) The count-and-say sequence is the sequence of integers beginning as follows:1, ...
- LeetCode第[18]题(Java):4Sum 标签:Array
题目难度:Medium 题目: Given an array S of n integers, are there elements a, b, c, and d in S such that a + ...
- LeetCode第[1]题(Java):Two Sum 标签:Array
题目: Given an array of integers, return indices of the two numbers such that they add up to a specifi ...
- LeetCode的刷题利器(伪装到老板都无法diss你没有工作)
在工程效率大行其道的今天,如果不会写点代码以后也不容易在测试圈混下去.今天给大家推荐一个LeetCode的刷题利器,可以伪装到连你老板在这里走过去都无法确认你是在干活呢,还是在干活呢. LeetCod ...
随机推荐
- OpenERP(odoo)开发实例之搜索检索过去3个月的数据
转自:http://www.chinamaker.net/ OpenERP(odoo)开发实例之搜索过滤:检索过去3个月的数据 解决这个问题的重点在于 relativedelta 的应用 示例代码如下 ...
- Java基础——线程总结
Java基础--线程总结 一.线程是什么? 线程:一个程序里不同的运行路径. 二.怎样创建线程? 两种方法创建线程: 第一种 (1)定义详细功能类实现Runnable接口,能够多次调用而实现数据共享 ...
- iOS-UICollectionView快速构造/拖拽重排/轮播实现
代码地址如下:http://www.demodashi.com/demo/11366.html 目录 UICollectionView的定义 UICollectionView快速构建GridView网 ...
- Call to undefined function mysql_connect()
Fatal error: Call to undefined function mysql_connect() in /data/www/qy_b2b/include/db_mysql.class.p ...
- python hello wlord
入门运行第一个python程序 https://www.python.org/ 官网下载最新python3安装到电脑 安装成功 cmd进入到安装目录 1.在cmd中直接进入到python安装目录 编写 ...
- js 时间毫秒
1. "2014-08-18 00:00:00" 与 13位毫秒 互换 var oTime = { _format_13_time:function (str){ var tim ...
- 取SQL分组中某几行数据
常用的方法有:子查询.ROW_NUMBER.APPLY,总体感觉还是ROW_NUMBER比较直观 if OBJECT_ID('testGroup') is not null drop table te ...
- unity, 不要用TextMesh,用图片代替
<方块鸭快跑>(见:http://www.cnblogs.com/wantnon/p/4596222.html)1.0版本开始界面中鸭子的speech bubble中的文字用的是TextM ...
- Android在非UI线程中更新UI的方法
1.使用Thread+Handler实现非UI线程更新UI界面 在UI Thread中创建Handler.用sendMessage(message)或者obtainMessage(result, ob ...
- Atitit.异常的设计原理与 策略处理 java 最佳实践 p93
Atitit.异常的设计原理与 策略处理 java 最佳实践 p93 1 异常方面的使用准则,答案是:: 2 1.1 普通项目优先使用异常取代返回值,如果开发类库方面的项目,最好异常机制与返回值都提供 ...