693. Binary Number with Alternating Bits
来源:互联网 发布:公司网站数据库在哪里 编辑:程序博客网 时间:2024/06/05 17:32
Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.
Example 1:
Input: 5Output: TrueExplanation:The binary representation of 5 is: 101
Example 2:
Input: 7Output: FalseExplanation:The binary representation of 7 is: 111.
Example 3:
Input: 11Output: FalseExplanation:The binary representation of 11 is: 1011.
Example 4:
Input: 10Output: TrueExplanation:The binary representation of 10 is: 1010.
class Solution { public boolean hasAlternatingBits(int n) { int d = n & 1 ; while((n & 1) == d){ d = 1-d ; n >>= 1 ; } return n == 0 ; }}
阅读全文
0 0
- leetcode 693. Binary Number with Alternating Bits
- 693. Binary Number with Alternating Bits
- 693. Binary Number with Alternating Bits
- leetcode 693. Binary Number with Alternating Bits
- LeetCode-693. Binary Number with Alternating Bits
- 693. Binary Number with Alternating Bits
- 693. Binary Number with Alternating Bits
- 693. Binary Number with Alternating Bits
- LeetCode 693. Binary Number with Alternating Bits
- 693. Binary Number with Alternating Bits
- leetcode 693. Binary Number with Alternating Bits
- Binary Number with Alternating Bits
- LWC 53:693. Binary Number with Alternating Bits
- python--leetcode693. Binary Number with Alternating Bits
- Binary Number with Alternating Bits(leetcode)
- Binary Number with Alternating Bits问题及解法
- leetcode 693. Binary Number with Alternating Bits(附正则表达式)
- LeetCode 693 Binary Number with Alternating Bits 带有交替位的二进制数
- 【java基础】19.网络编程
- js写排序的方法。
- [Office] 常用的一些快捷键 [持续更新]
- 使用 xml 保存通讯录信息
- js数组方法大全
- 693. Binary Number with Alternating Bits
- 选择一款大数据可视化展示工具,要几步?
- 杜绝假死,Tomcat容器做到自我保护,设置最大连接数
- Python 从入门到放弃(二)
- 加密,解密工具类
- python爬虫 如何解析json文件 json文件的解析提取和jsonpath的应用
- 基于图的图像分割(Graph-Based Image Segmentation)
- 一键配置LVS,DR模式脚本
- nodejs npm install全局安装和本地安装的区别及配置