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)的更多相关文章

  1. LeetCode 第 342 题(Power of Four)

    LeetCode 第 342 题(Power of Four) Given an integer (signed 32 bits), write a function to check whether ...

  2. LeetCode 第 342 题(Power of Four)

    LeetCode 第 342 题(Power of Four) Given an integer (signed 32 bits), write a function to check whether ...

  3. 【JavaScript】Leetcode每日一题-平方数之和

    [JavaScript]Leetcode每日一题-平方数之和 [题目描述] 给定一个非负整数 c ,你要判断是否存在两个整数 a 和 b,使得 a2 + b2 = c . 示例1: 输入:c = 5 ...

  4. 【python】Leetcode每日一题-矩阵置零

    [python]Leetcode每日一题-矩阵置零 [题目描述] 给定一个 m x n 的矩阵,如果一个元素为 0 ,则将其所在行和列的所有元素都设为 0 .请使用 原地 算法. 进阶: 一个直观的解 ...

  5. leetcode 第188题,我的解法,Best Time to Buy and Sell Stock IV

    <span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255) ...

  6. leetcode第37题--Count and Say

    题目:(据说是facebook的面试题哦) The count-and-say sequence is the sequence of integers beginning as follows:1, ...

  7. 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 + ...

  8. 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 ...

  9. LeetCode的刷题利器(伪装到老板都无法diss你没有工作)

    在工程效率大行其道的今天,如果不会写点代码以后也不容易在测试圈混下去.今天给大家推荐一个LeetCode的刷题利器,可以伪装到连你老板在这里走过去都无法确认你是在干活呢,还是在干活呢. LeetCod ...

随机推荐

  1. 【树莓派】Box相关手册-4 Web代理

    在盒子上安装配置web代理,通过此代理,用户访问盒子的内网地址实现web portal访问.目前我们使用tinyproxy作为web代理 安装: >sudo apt-get install ti ...

  2. 如何利用ps去批量完成一套任务

    作为前端开发人员,不说设计你会不会,ps作为一个工具来说,前端开发人员还是要熟悉才行的 做了一个项目,客户自己上传了图片,他表示上传非常慢,我们表示不解,为何那么慢,网络问题吗,经过看了她的图片,发现 ...

  3. STL源码剖析(仿函数/bind2nd)

    仿函数(functors)其实就是重载了operator()的对象. 下面简单先看看它的一个例子: #include <iostream> using namespace std; tem ...

  4. js实现页面跳转的两种方式

      CreateTime--2017年8月24日08:13:52Author:Marydon js实现页面跳转的两种方式 方式一: window.location.href = url 说明:我们常用 ...

  5. MySQL数据迁移问题

    最近尝试了一下小型数据迁移.本地迁移,windows平台,修改配置文件中的data_dir项,然后将旧的data文件下的数据文件全部拷贝过去. 之后登陆数据库,竟然1145错误.可以看到数据库的结构, ...

  6. vs2017安装过程问题及解决方法

    1. 问题:C++ 无法打开 源 文件 "errno.h"等文件 解决方法:https://jingyan.baidu.com/article/8ebacdf0167b2249f6 ...

  7. python内置函数、匿名函数、递归

    python3--内置函数 内置函数: 截止到python 3.6.2 版本,现在python一共提供了68个内置函数:即python提供给你直接可以拿来使用的所有函数.   内置函数  (点击函数查 ...

  8. Android 混淆代码总结

    为了防止自己的劳动成果被别人窃取,混淆代码能有效防止被反编译,下面来总结以下混淆代码的步骤: 1. 大家也许都注意到新建一个工程会看到项目下边有这样proguard-project.txt一个文件,这 ...

  9. python list插入、拼接

    1可以使用"+"号完成操作 输出为: [1, 2, 3, 8, 'google', 'com'] 2.使用extend方法 . 输入相同 3使用切片 输出相同 PS:len(l1) ...

  10. .Net程序员面试 每个人都应知道篇 (回答Scott Hanselman的问题)

    昨天回答了Scott Hanselman在他清单上关于C#那部分的题目,.Net 程序员面试 C# 语言篇 (回答Scott Hanselman的问题),今天接着回答他在清单上列出的"每个写 ...