当前位置:网站首页>693. alternate bit binary number
693. alternate bit binary number
2022-06-27 05:55:00 【Mr Gao】
693. Alternate bit binary number
Given a positive integer , Check that its binary representation is always 0、1 Appear alternately : let me put it another way , That is, the numbers of two adjacent digits in binary representation will never be the same .
Example 1:
Input :n = 5
Output :true
explain :5 The binary representation of is :101
Example 2:
Input :n = 7
Output :false
explain :7 The binary representation of is :111.
Example 3:
Input :n = 11
Output :false
explain :11 The binary representation of is :1011.
The solution code is as follows :
bool hasAlternatingBits(int n){
int pre=n%2;
n=n/2;
int t;
while(n){
t=n%2;
if(t==pre){
return false;
}
else{
n=n/2;
pre=t;
}
}
return true;
}
边栏推荐
- Unicast, multicast and broadcast of IP network communication
- Win 10 如何打开环境变量窗口
- 创建一个基础WDM驱动,并使用MFC调用驱动
- Configuring the help class iconfiguration in C # NETCORE
- JS to implement bidirectional data binding
- Qt使用Valgrind分析内存泄漏
- Webrtc series - Nomination and ice of 7-ice supplement for network transmission_ Model
- 【FPGA】UART串口_V1.1
- MATLAB快速将影像的二维坐标转换为经纬度坐标
- [collection] Introduction to basic knowledge of point cloud and functions of point cloud catalyst software
猜你喜欢
QT using Valgrind to analyze memory leaks
使用域名转发mqtt协议,避坑指南
Software testing year end summary report template
Go log -uber open source library zap use
How JQ gets the ID name of an element
多线程基础部分Part2
Experience oceanbase database under win10
C Primer Plus 第11章_字符串和字符串函数_代码和练习题
Basic concepts of neo4j graph database
函数栈帧的形成与释放
随机推荐
[nips 2017] pointnet++: deep feature learning of point set in metric space
Epics record reference 5 -- array analog input recordarray analog input (AAI)
Go日志-Uber开源库zap使用
Program ape learning Tiktok short video production
Avoid asteroids
Comprehensive application of OpenCV in contour detection and threshold processing
Codeforces Round #802 (Div. 2)
Free SSH and telnet client putty
【Cocos Creator 3.5.1】坐标的加法
IP网络通信的单播、组播和广播
NEON优化1:软件性能优化、降功耗怎么搞?
KubeSphere 集群配置 NFS 存储解决方案-收藏版
【QT小点】实现看门狗功能,检测外部程序是否在运行
C# netcore中 配置帮助类IConfiguration
双位置继电器RXMVB2 R251 204 110DC
[FPGA] realize the data output of checkerboard horizontal and vertical gray scale diagram based on bt1120 timing design
汇编语言-王爽 第11章 标志寄存器-笔记
C语言实现定时器
DAST 黑盒漏洞扫描器 第六篇:运营篇(终)
The form verifies the variables bound to the V-model, and the solution to invalid verification