693. Binary Number with Alternating Bits
static int wing=[]()
{
std::ios::sync_with_stdio(false);
cin.tie(NULL);
return ;
}(); class Solution
{
public:
bool hasAlternatingBits(int n)
{
n^=n>>;
return (n&(n+))==;
}
};
这里用到了判定一个二进制n,位上全部为1的方法
(n&(n+1))==0
693. Binary Number with Alternating Bits的更多相关文章
- 【Leetcode_easy】693. Binary Number with Alternating Bits
problem 693. Binary Number with Alternating Bits solution1: class Solution { public: bool hasAlterna ...
- 693. Binary Number with Alternating Bits - LeetCode
Question 693. Binary Number with Alternating Bits Solution 思路:输入一个整数,它的二进制01交替出现,遍历其二进制字符串,下一个与上一个不等 ...
- [LeetCode&Python] Problem 693. Binary Number with Alternating Bits
Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will a ...
- 【LeetCode】693. Binary Number with Alternating Bits 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 遍历判断 判断是否是交替模式 位运算 日期 题目地址 ...
- LeetCode 693 Binary Number with Alternating Bits 解题报告
题目要求 Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits w ...
- [LeetCode] Binary Number with Alternating Bits 有交替位的二进制数
Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will a ...
- [Swift]LeetCode693. 交替位二进制数 | Binary Number with Alternating Bits
Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will a ...
- 987. Binary Number with Alternating Bits
Description Given a positive integer, check whether it has alternating bits: namely, if two adjacent ...
- [LeetCode] 693. Binary Number with Alternating Bits_Easy
Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will a ...
随机推荐
- checkbox/radio 样式修改
只改颜色 input[type=radio],input[type=checkbox] { display: inline-block; vertical-align: middle; width: ...
- 以太坊博弈游戏 -- FOMO3D,讽刺人性
以下资料收录自各个博客,下面给出链接. 总的来说,这是基于以太坊的“菠菜”游戏,大资金盘,亏多盈少,大家看看就好. 官网地址:http://exitscam.me/play 出现 7月16日,当时这个 ...
- TZOJ 4621 Grammar(STL模拟)
描述 Our strings only contain letters(maybe the string contains nothing). Now we define the production ...
- stark组件之搜索【模仿Django的admin】
一.先看下django的admin是如何做搜索功能的 配置一个search_fields的列表就可以实现搜索的功能 class testbook(admin.ModelAdmin): # 第一步,定义 ...
- stark组件之启动【模仿Django的admin】
首先需要在settings注册app INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib ...
- mysql 单表查询
一 单表查询的语法 SELECT 字段1,字段2... FROM 表名 WHERE 条件 GROUP BY field HAVING 筛选 ORDER BY field LIMIT 限制条数 二 ...
- Java图形化界面设计——GridBagConstraints
JAVA布局模式:GridBagConstraints终极技巧参数详解 布局模式 :GridBagConstraints布局,先发一个实例: gridx = 2; // X2 gridy = 0; / ...
- String 练习
package com.hanqi; import java.util.Random; public class Text { public static void main(String[] arg ...
- The 10 Best Choices On The Market Review 2018
Looking to buy a scan tool or considering one of Autel Scanner impressive product line?. The company ...
- android xml 解析汉字只出来一个字的问题
DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance(); // 实例化DocumentBuilder factor ...