leetcode693
- class Solution {
- public:
- bool hasAlternatingBits(int n) {
- int last = -;
- while (n)
- {
- int x = n & ;
- if (last == -)
- {
- last = x;
- }
- else
- {
- if (x == last)
- {
- return false;
- }
- else
- {
- last = x;
- }
- }
- n >>= ;//n右移1位
- }
- return true;
- }
- };
leetcode693的更多相关文章
- [Swift]LeetCode693. 交替位二进制数 | Binary Number with Alternating Bits
Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will a ...
- leetcode693:Binary Number with Alternating Bits
判断一个数字的二进制形式是不是01交替的. 如5=101,返回True 如7=111,返回False 这道题可以用位运算来实现.看到01交替,就想到移位运算.如果n是01交替的,移位之后进行异或,则得 ...
- Leetcode693.Binary Number with Alternating Bits交替位二进制数
给定一个正整数,检查他是否为交替位二进制数:换句话说,就是他的二进制数相邻的两个位数永不相等. 示例 1: 输入: 5 输出: True 解释: 5的二进制数是: 101 示例 2: 输入: 7 输出 ...
随机推荐
- Ceph与OpenStack整合(仅为云主机提供云盘功能)
1. Ceph与OpenStack整合(仅为云主机提供云盘功能) 创建: linhaifeng,最新修改: 大约1分钟以前 ceph ceph osd pool create volumes 128 ...
- LeetCode OJ:Three Sum(三数之和)
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all un ...
- OC-SEL 和 Class
[认识选择器]============================================ SEL 1.选择器(SEL)是一个变量类型. 2.选择器用来装成员消息(成员方法) people ...
- CoreData之增删改查
1. 导入库文件CoreData.framework2. 在iOS的Core Data 中建Data Model文件 此时有三种选择 2.1. 选Data Model(如默认名Model.xcdata ...
- <input type="checkbox" name="" value=" ">
<input type="checkbox" name="" value=" ">
- New Concept English three (42)
21 33 Cave exploration, or pot-holing, as it has come to be known, is a relatively new sport. Perhap ...
- opencv roi resize 会导致内存拷贝产生子图像
opencv roi区域 resize之后,roi的引用已不是原图的引用,而是内存拷贝产生的子图像. http://blog.csdn.net/qianqing13579/article/detail ...
- Java进阶知识点4:不可变对象与并发 - 从String说起
一.String的不可变特性 熟悉Java的朋友都知道,Java中的String有一个很特别的特性,就是你会发现无论你调用String的什么方法,均无法修改this对象的状态.当确实需要修改Strin ...
- HDU - 6096 :String (AC自动机,已知前后缀,匹配单词,弱数据)
Bob has a dictionary with N words in it. Now there is a list of words in which the middle part of th ...
- C# 通过窗口句柄获取程序路径 图标
转自:http://qqhack8.blog.163.com/blog/static/11414798520113363829505/ C# 通过窗口句柄获取程序路径 图标using System;u ...