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 ...
随机推荐
- 第13届景驰-埃森哲杯广东工业大学ACM程序设计大赛----随手记录帖
这是跟学长学姐组队来打的最爽的一次比赛了,也可能是互相组队最后一次比赛了,南哥和楼学姐,省赛之后就退役了,祝他们能考研和面试都有happy ending! 虽然最后没有把F题的n^2约数的数学题写完, ...
- oracle中取得当前日期,前一天,当前月,前一个月
当前日:select TRUNC(SYSDATE) from dual; 前一天: select TRUNC(SYSDATE - 1) from dual; 前一天转换为日期格式: select ...
- jQuery Grid高级指南
上周以为已经把jqgrid 表格这部分已经搞得差不多了,没想到在实际用的时候,出现了不少问题,重新把这块知识整理一下. 问题一:设置表格的自动刷新 问题的原因: 使用表格自带的增删改查的功能,编辑完数 ...
- FortiGate设备管理
1.Web管理 1.FortiGate出厂配置 默认地址为192.168.1.99,可以通过https的方式进行web管理(默认用户名admin,密码为空).不同型号设备用于管理的接口略有不同,如: ...
- C语言常用关键字及运算符操作
1.关键字 (1)数据类型 char 1字节,8bit==256 int long,short unsgined ,signed 无符号为 ...
- VS2010,VS2012,VS2013中,无法嵌入互操作类型“……”,请改用适用的接口的解决方法
在VS2013开发环境下,C#引用COM组件遇到的两个问题: 一开始是COM组件没有注册导致代码引用报错,那么我就使用管理员的命令行方式下,入册COM组件: C:\WINDOWS\system32&g ...
- Navicat premiu的导入和导出
对于Navicat premiu(数据库管理工具)中对于数据库的导出和导入步骤如下: 1.选择要导出的数据库->转储SQL文件->选择结构和数据或结构->选择存放的路径,即可导出成功 ...
- angular 1.x 控制器之间互相传递参数
我们要向前方看齐,基于js引用类型的对象就不记了,所以使用基于事件的方式: angular 中 $on,$emit,$boardcast来实现父控制器和子控制器互相通讯, 其中$on表示事件监听, $ ...
- Svn Server 强制提交者输入注释信息
目的:在项目开发过程中,强制团队成员必须在提交前写上注释 环境简述:SVN服务器:Windows Server 2008 SVN版本:VisualSVN Ltd. 2.7.5 操作方法:在SVN的R ...
- c#程序设计原则
单一职责 开闭原则:对扩展开放,对修改封闭. 方法 的职责,一个方法做的事越多,造成问题的可能性会增加. 解决的方法1:就是分拆2:写单独类