leetcode 693. Binary Number with Alternating Bits
来源:互联网 发布:数据挖掘 需要学c 编辑:程序博客网 时间:2024/06/06 02:19
693. Binary Number with Alternating Bits
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: bool hasAlternatingBits(int n) { //解法2 int k=n&1; n>>=1; while (n){ int j=n&1; if (k==j)return false; k=j; n>>=1; } 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问题及解法
- 第一条复杂SQL(对账周期汇总表)
- 使用@JsonSerialize对javabean进行json格式化
- 2.malloc()与new
- 关于cookie的详细讲解
- String、StringBuffer与StringBuilder的区别
- leetcode 693. Binary Number with Alternating Bits
- php字符串的定义方式及区别
- PHP之抽象类、接口
- Could not initialize class net.sf.json.util.JSONUtils
- 剑指offer 数组
- 前端高性能计算之一:WebWorkers
- 简单聊聊Android Architecture Componets
- leetcode 215. Kth Largest Element in an Array
- 路由协议攻击