当前位置:网站首页>LeetCode做题小结
LeetCode做题小结
2022-08-09 16:59:00 【Mosquito...】
1. 移位运算的运用
1. 将二进制转化为十进制
通过移位得到结果,另外一种方法是采用 2 0 ⋅ x 0 + 2 1 ⋅ x 1 + . . . + 2 n ⋅ x n 2^0\cdot x_0+2^1\cdot x_1+...+2^n\cdot x_n 20⋅x0+21⋅x1+...+2n⋅xn得到,但注意无符号整数类型和有符号整数类型的判断,不考虑的话直接采用第二种方法可能会导致溢出。
// number[i]存储第i位的数值(从地位开始计算,即number[0]的权值为1,number[1]的权值为2,依次类推
for (int i = 0; i < 32; ++i) {
//res += number[i] * pow(2, i); 这样可能会产生上溢出
res = res | (number[i] << i);
}
2. 乘以2除以2的计算
直接用移位运算即可
边栏推荐
猜你喜欢
随机推荐
进程的两种创建方式,join方法,进程间的数据隔离,队列,进程间的通信IPC机制,生产者消费者模型,守护进程,僵尸进程,孤儿进程,互斥锁
[SUCTF 2019]CheckIn
字节也开始缩招了...
Jenkins使用pipeline部署服务到远程服务器
Apache Doris Community PMC Yang Zhengguo: How do open source projects strike a balance between their own and the community's needs?
Guo Wei (Guo Daxia): Nine Yes or No about open source
leetcode/链表中环的入口节点
win10 uwp 装机必备应用 含源代码
C#介绍及基本数据类型
微软 .NET Core 3.1 年底将结束支持,请升级到.NET 6
win10 uwp 简单MasterDetail
International Soil Modeling Consortium-ISMC
试试使用 Vitest 进行组件测试,确实很香。
谭中意:你知道 “开源女王” 是谁吗?
Logic unauthorized and horizontal and vertical unauthorized payment tampering, verification code bypass, interface
One-key login principle of local number
进行知识管理的好处有哪些?
动手学深度学习_风格迁移
Jenkins deploys services to remote servers using pipelines
WPF 实现柱形统计图








