693. Binary Number with Alternating Bits
static int wing=[]()
{
std::ios::sync_with_stdio(false);
cin.tie(NULL);
return ;
}(); class Solution
{
public:
bool hasAlternatingBits(int n)
{
n^=n>>;
return (n&(n+))==;
}
};
这里用到了判定一个二进制n,位上全部为1的方法
(n&(n+1))==0
693. Binary Number with Alternating Bits的更多相关文章
- 【Leetcode_easy】693. Binary Number with Alternating Bits
problem 693. Binary Number with Alternating Bits solution1: class Solution { public: bool hasAlterna ...
- 693. Binary Number with Alternating Bits - LeetCode
Question 693. Binary Number with Alternating Bits Solution 思路:输入一个整数,它的二进制01交替出现,遍历其二进制字符串,下一个与上一个不等 ...
- [LeetCode&Python] Problem 693. Binary Number with Alternating Bits
Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will a ...
- 【LeetCode】693. Binary Number with Alternating Bits 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 遍历判断 判断是否是交替模式 位运算 日期 题目地址 ...
- LeetCode 693 Binary Number with Alternating Bits 解题报告
题目要求 Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits w ...
- [LeetCode] Binary Number with Alternating Bits 有交替位的二进制数
Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will a ...
- [Swift]LeetCode693. 交替位二进制数 | Binary Number with Alternating Bits
Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will a ...
- 987. Binary Number with Alternating Bits
Description Given a positive integer, check whether it has alternating bits: namely, if two adjacent ...
- [LeetCode] 693. Binary Number with Alternating Bits_Easy
Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will a ...
随机推荐
- js,JavaScript,a标签onclick传递参数不对,A标签调用js函数写法总结
错误示例: <a href="javascript:waterLineEdit(${goods.goods_id})" >修改 </a> <!-- 浏 ...
- Camera插件推荐,解锁电影大师级视角控制
相机在游戏中的重要性是不言而喻的,尤其是一些MMORPG或FPS等类型的游戏,相机不仅需要跟随游戏主角进行移动,可能还要随时准备切换焦点,这就要求开发者将游戏相机管理得井井有条,能顺应游戏中可能瞬息发 ...
- 浅谈CSRF
CSRF是什么? (Cross Site Request Forgery, 跨站域请求伪造)是一种网络的攻击方式,它在 2007 年曾被列为互联网 20 大安全隐患之一,也被称为“One Click ...
- 【laravel VS lumen】
读取项目的配置信息 读取config文件database.php中的default属性信息 laravel:config('database.default'); lumen:app()->co ...
- OC 线程操作1 - pthread
#import "ViewController.h" #import <pthread.h> //1.需要包含这个头文件 @interface ViewControll ...
- dup
dup是一个操作符,由编译器识别处理,和db.dw.dd等数据定义伪指令配合使用,用来进行数据的重复. 例如 db 3 dup (0) 定义了3个字节,它们的值都是0,相当于db 0,0,0 db ...
- mysql 复制原理与实践
复制功能是将一个mysql数据库上的数据复到一个或多个mysql从数据库上. 复制的原理:在主服务器上执行的所有DDL和DML语句都会被记录到二进制日志中,这些日志由连接到它的从服务器获取,并复制到从 ...
- golang 通过fsnotify监控文件,并通过文件变化重启程序
一.下载我们需要的包 > go get github.com/fsnotify/fsnotify 二.使用fsnotify监控文件 package main; import ( "gi ...
- .net 下存取Excel的利器(第三方)
NPOI 资料: NPOI是什么?能干什么? 个人理解:NPOI是个操作Excel的第三方类库.可以在没有安装Office的情况下,处理Excel文件. 官方网站-NPOI指南:http://www. ...
- 8I - 吃糖果
HOHO,终于从Speakless手上赢走了所有的糖果,是Gardon吃糖果时有个特殊的癖好,就是不喜欢将一样的糖果放在一起吃,喜欢先吃一种,下一次吃另一种,这样:可是Gardon不知道是否存在一种吃 ...