当前位置:网站首页>【剑指offer65】不适用加减乘除做加法
【剑指offer65】不适用加减乘除做加法
2022-08-09 02:21:00 【星光技术人】
不适用加减乘除做加法
题目
解题
使用位运算,10进制的加减法,计算两个数的和的个数,进位数,相加;code
class Solution {
public:
int add(int a, int b) {
if(b==0)
return a;
return add(a^b,(unsigned int)(a&b)<<1);
}
};
使用unsingeed int是因为C++不支持负值左移,要用unsign int;并且使用ubsigned int会把第一个索引位置0变为1,但是接着就要左移,所以对结果没有影响
边栏推荐
猜你喜欢
ROS2错误:不支持OpenGL 1.5 GLRenderSystem:: ci initialiseContext在C: \ \ ws \构建……
js实现数组去重的方式(7种)
HNUMSC-C语言第一课
Etcd realize large-scale application service management of actual combat
电磁辐射安全标准及检测方法
危化企业双预防机制数字化建设工作要求
力扣刷题记录3.1-----977. 有序数组的平方
SQLite切换日志模式优化
MT4 / MQ4L entry to the master of EA tutorial lesson two (2) - - MQL language commonly used function account information commonly used functions
力扣刷题记录9.1-----24. 两两交换链表中的节点
随机推荐
Go-11 - Process Control
The security of the pension insurance?Reliable?
2020.10.13 Development log
D. Tournament Countdown
Go-8-Gin framework
基于JMF视频聊天
JDBC技术(二)——设置通用的sql和配置文件
Codeforces Round #809 (Div. 2)A~D1
2.1-----27. Remove elements
工具类:base64格式的数据与本地文件的相互转换
Likou Brush Question Record--Common Functions
力扣刷题记录10.1-----19. 删除链表的倒数第 N 个结点
.reduce()的简单例子
最新工业界推荐系统数据集-召回排序模型原理、结构及代码实战整理分享
NPDP改版前最后一次考试!请注意
如何最大限度地减少企业受到供应链攻击的风险
Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules
Summary of pytorch related knowledge points
Using ngrok on Raspberry Pi (Extra 2)
The 7 taboos of time management summarized by the postgraduate students, how many have you won?