【C++刷题】位运算
发布时间:2024年01月13日

一、二进制中最右侧的1
1、位1的个数
(1)题目链接
leetcode链接

(2)解析

(3)代码

2、比特位计数
(1)题目链接
leetcode链接

(2)解析


(3)代码

3、汉明距离
(1)题目链接
leetcode链接

(2)解析
两个数异或一下,因为异或一下不同的数为1,相同的数为0,所以能够找到有几个不同数的位置了,再逐个干掉右边的1,ret++即可。
(3)代码

二、异或规律
1、只出现一次的数字
(1)题目链接
leetcode链接

(2)解析

(3)代码

2、只出现一次的数字III
(1)题目链接
leetcode链接

(2)解析

(3)代码

三、判定字符是否唯一
1、题目链接
leetcode链接

2、解析

3、代码

四、丢失的数字
1、题目链接
leetcode链接

2、解析+代码

五、两整数之和
1、题目链接
leetcode链接

2、解析
先疑惑求一个值,再按位与右移算出另一个控制的进位值。

3、代码

六、只出现一次的数字II
1、题目链接
leetcode链接

2、解析

3、代码

七、消失的两个数字
1、题目链接
leetcode链接

2、解析

3、代码

文章来源:https://blog.csdn.net/m0_70088010/article/details/135167364
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:chenni525@qq.com进行投诉反馈,一经查实,立即删除!