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

  1. [Swift]LeetCode693. 交替位二进制数 | Binary Number with Alternating Bits

    Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will a ...

  2. leetcode693:Binary Number with Alternating Bits

    判断一个数字的二进制形式是不是01交替的. 如5=101,返回True 如7=111,返回False 这道题可以用位运算来实现.看到01交替,就想到移位运算.如果n是01交替的,移位之后进行异或,则得 ...

  3. Leetcode693.Binary Number with Alternating Bits交替位二进制数

    给定一个正整数,检查他是否为交替位二进制数:换句话说,就是他的二进制数相邻的两个位数永不相等. 示例 1: 输入: 5 输出: True 解释: 5的二进制数是: 101 示例 2: 输入: 7 输出 ...

随机推荐

  1. Oracle RAC(Real Application Clusters)

    Oracle RAC 运行于集群之上,为 Oracle 数据库提供了最高级别的可用性.可伸缩性和低成本计算能力.如果集群内的一个节点发生故障,Oracle 将可以继续在其余的节点上运行.Oracle ...

  2. react: next-redux-saga

    instead of using the Provider component, you can use the withRedux higher order component to inject ...

  3. Agilent RF fundamentals (5)

    2考虑两个因素 3 RX 4 TX RX switch use Duplexer

  4. 【dlbook】深度网络

    前向网络:无反馈 feedback 连接 [输出单元] 线性 -- 高斯分布 . sigmoid单元 -- bernoulli输出. softmax单元 -- multinoulli [隐藏单元] 整 ...

  5. 关于SQL Sever连接问题

    错误: 与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误.未找到或无法访问服务器.请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接. (provider: ...

  6. 使用BloomFilter布隆过滤器解决缓存击穿、垃圾邮件识别、集合判重

    Bloom Filter是一个占用空间很小.效率很高的随机数据结构,它由一个bit数组和一组Hash算法构成.可用于判断一个元素是否在一个集合中,查询效率很高(1-N,最优能逼近于1). 在很多场景下 ...

  7. git配置ssh key并从github.com拉取repos

    一.配置ssh key 1. 进入当前用户目录cd ~2. 生成ssh keyssh-keygen -t rsa -C "ABC@qq.com"ABC@qq.com账号必须是你登录 ...

  8. 【英语】Bingo口语笔记(82) - go系列

  9. sql_自连接,181,182,196,197

    181. Employees Earning More Than Their Managers https://leetcode.com/problems/employees-earning-more ...

  10. sqlalchemy的缓存和刷新

    其实只是第一次查询了数据库,其他的时候都使用的是缓存,所以有时候,因为这个特性会出错,所以需要刷新对象或者使对象过期 参考链接:http://www.cnblogs.com/fengyc/p/5369 ...