当前位置:网站首页>693. 交替位二进制数
693. 交替位二进制数
2022-06-27 05:40:00 【Mr Gao】
693. 交替位二进制数
给定一个正整数,检查它的二进制表示是否总是 0、1 交替出现:换句话说,就是二进制表示中相邻两位的数字永不相同。
示例 1:
输入:n = 5
输出:true
解释:5 的二进制表示是:101
示例 2:
输入:n = 7
输出:false
解释:7 的二进制表示是:111.
示例 3:
输入:n = 11
输出:false
解释:11 的二进制表示是:1011.
解题代码如下:
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;
}
边栏推荐
- Mechanical transcoding journal [17] template, STL introduction
- Navigation [machine learning]
- 导航【机器学习】
- Luogu p2939 [usaco09feb]revamping trails G
- 【622. 设计循环队列】
- RTP sending PS stream tool (open source)
- AD22 gerber files 点开 gerber steup 界面 有问题 官方解决方法
- Opencv implements object tracking
- Unicast, multicast and broadcast of IP network communication
- Two position relay rxmvb2 r251 204 110dc
猜你喜欢
![Navigation [machine learning]](/img/79/8311a409113331e72f650a83351b46.png)
Navigation [machine learning]

Codeforces Round #802 (Div. 2)

Niuke practice 101-c reasoning clown - bit operation + thinking

双位置继电器JDP-1440/DC110V

快速排序(非递归)和归并排序
![[FPGA] realize the data output of checkerboard horizontal and vertical gray scale diagram based on bt1120 timing design](/img/80/c258817abd35887c0872a3286a821f.png)
[FPGA] realize the data output of checkerboard horizontal and vertical gray scale diagram based on bt1120 timing design

Codeforces Round #802 (Div. 2)

齐纳二极管 稳压二极管 SOD123封装 正负区分

Two position relay hjws-9440

leetcode-20. Valid parentheses -js version
随机推荐
快速排序(非遞歸)和歸並排序
Neon optimization 1: how to optimize software performance and reduce power consumption?
思维的技术:如何破解工作生活中的两难冲突?
leetcode-20. Valid parentheses -js version
Spark 之 WholeStageCodegen
ES6 0622 III
导航【机器学习】
AcWing 第 57 场周赛---BC题挺好
Epics record reference 5 -- array analog input recordarray analog input (AAI)
Acwing's 57th weekly match -- BC question is very good
微信小程序WebSocket使用案例
函数式 连续式
DAST black box vulnerability scanner part 6: operation (final)
Leetcode298 weekly race record
EasyExcel合并相同内容单元格及动态标题功能的实现
Flink production problems (1.10)
Spark 之 built-in functions
DAST 黑盒漏洞扫描器 第六篇:运营篇(终)
stm32读取IO高低电平状态
双位置继电器RXMVB2 R251 204 110DC