当前位置:网站首页>【剑指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 \构建……
- 物联网未来:未来五年的预期
- MT4/MQL4入门到精通EA课程第二课-常用的功能函数
- [ANT]apache ant 安装说明
- A40i gxl3680 ts_print报错:tslib: Selected device is not a touchscreen (must support ABS and KEY event
- MT4/MQL4入门到精通外汇EA教程第一课 认识MetaEditor
- 使用JS实现数组扁平化的几种方式
- <爆>2022中文版-《海外博士申请指南-材料准备、时间线、套磁、面试及录取》免费分享
- 17.flink Table Api基础概念讲解
- Z-Game on grid
猜你喜欢
A40i gxl3680 ts_print报错:tslib: Selected device is not a touchscreen (must support ABS and KEY event
力扣刷题记录4.1-----209. 长度最小的子数组
JDBC技术(一)——一个简单的JDBC测试
mysql 5.7 入坑
Line segment tree of knowledge
企业面临的五大数据安全挑战
数仓第一篇:基础架构
D. Tournament Countdown
Data recovery software EasyRecovery supports recovery of all types of files
企业从云服务的承诺支出中获得最大收益的四种方法
随机推荐
2022眼康品牌加盟展,北京视力保健展,中国眼科医学技术峰会
Difference between KQL and Lucene
2022 PMP Project Management Certification Exam Registration Guide (1)
Significance Test--Study Notes
The last exam before the NPDP revision!caution
NPDP改版前最后一次考试!请注意
2022年自然语言处理校招社招实习必备知识点盘点分享
gpio子系统和pinctrl子系统(上)
电磁辐射安全标准及检测方法
力扣刷题记录1.5-----367. 有效的完全平方数
2.1-----27. Remove elements
10.1-----19. Delete the Nth node from the bottom of the linked list
Etcd realize large-scale application service management of actual combat
Use of torchversion.transforms
pytorch相关知识点总结
New Swagger3.0 tutorial, OAS3 quick configuration guide, to automate API interface documentation!
The first lesson of HNUMSC-C language
What is the difference between a project manager and a product manager?
spdlog日志库的封装使用
Z-Game on grid(牛客多校赛)