LeetCode:Sum of Two Integers
2016-07-05 21:01
417 查看
Sum of Two Integers
Calculate the sum of two integers a and b, but you are not allowed to use the operator +and
-.
Example:
Given a = 1 and b = 2, return 3.
Credits:
Special thanks to @fujiaozhu for adding this problem and creating all test cases.
Subscribe to see which companies asked this question
Hide Tags
Bit Manipulation
Hide Similar Problems
(M) Add Two Numbers
思路:
之前总结的:位操作实现加减乘除四则运算
c++ code:
class Solution { public: int getSum(int a, int b) { int c; // 进位 while(b) { c = (a & b) << 1; a = a ^ b; b = c; } return a; } };
相关文章推荐
- Undefined symbols for architecture armv7: 解决方案
- 使用Angular Resources 封装Rest API
- Navicat For Mysql快捷键
- 调用手机相机拍照并裁剪相片
- Mysql6.0连接中的几个问题
- eclipse各个版本介绍(转)
- 1443. Printer Queue
- 最常用--正则表达式列表
- 360°全景照片
- poj3253
- Ubantu下的输入法--小巧有用
- 文章标题
- Erlang调度器的一些细节以及它重要的原因(译文)
- IDEA 下开发web项目部署时,配置文件没有编译的问题
- [bzoj1969] [Ahoi2005]LANE 航线规划
- MapReduce程序的3种集群提交运行模式详解---基于Windows与Linux两种开发环境
- 【Unity Shader】自定义材质面板的小技巧
- UNIX网络编程——并发服务器(多进程)
- Python读取等宽数据文件
- 3、继承