leetcode 693. Binary Number with Alternating Bits
来源:互联网 发布:智能电视看美剧软件 编辑:程序博客网 时间:2024/06/06 00:39
原题:
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.
代码如下:
bool hasAlternatingBits(int n) { int temp=-1; while(n!=0) { if(temp==n%2) { return false; } else { temp=n%2; n=(n-temp)/2; } } return true;}
这个就说啥了。。
阅读全文
0 0
- leetcode 693. Binary Number with Alternating Bits
- leetcode 693. Binary Number with Alternating Bits
- LeetCode-693. Binary Number with Alternating Bits
- LeetCode 693. Binary Number with Alternating Bits
- leetcode 693. Binary Number with Alternating Bits
- 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
- 693. Binary Number with Alternating Bits
- 693. Binary Number with Alternating Bits
- Binary Number with Alternating Bits
- leetcode 693. Binary Number with Alternating Bits(附正则表达式)
- LWC 53:693. Binary Number with Alternating Bits
- python--leetcode693. Binary Number with Alternating Bits
- LeetCode 693 Binary Number with Alternating Bits 带有交替位的二进制数
- Binary Number with Alternating Bits问题及解法
- JavaScript是如何工作的:内存管理 + 如何处理4个常见的内存泄露
- docker compose
- HTML杂记
- Spring自定义注解+Aop记录用户操作日志
- 公众号客服怎么接入客户-微信公众号使用教程23
- leetcode 693. Binary Number with Alternating Bits
- mybatis简单案例源码详细【注释全面】——前期准备
- 设备管理器总结
- port 3306 already in use
- 操作系统页面置换算法(opt,lru,fifo,clock)实现
- vim基本设置
- 【转】手工导入传输请求(Transport Request)
- 【正一专栏】稳定压倒一切
- C语言 unsigned与signed区别