371. Sum of Two Integers
来源:互联网 发布:上海女人护肤品 知乎 编辑:程序博客网 时间:2024/05/21 08:45
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.
class Solution {public: int getSum(int a, int b) { int carry = 0, num = 0, bita, bitb; for(int i = 0; i < 32; ++i) { bita = a & (1<<i); bitb = b & (1<<i); carry = (carry<<i); num |= bita ^ bitb ^ carry; if((bita & bitb) || (bita & carry) || (bitb & carry)) carry = 1; else carry = 0; } return num; }};
0 0
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 371. Sum of Two Integers
- 淘宝SKU组合查询算法实现
- iOS UIWebView 的下拉刷新和上拉加载的实现
- 数据挖掘在公共建筑能耗分析中的应用研究
- 关于下载的.chm文件,点击目录无内容显示,已解决
- 百度与谷歌技术实力比较
- 371. Sum of Two Integers
- Hibernate openSession() 和 getCurrentSession的区别
- MFC 双缓冲 绘图实例
- 离线轻量级大数据平台Spark之MLib机器学习库Word2Vec实例
- RMS (Rights Management Services)基于SDK2.1的二次开发环境搭建
- angular中的$provide和$inject方法使用理解
- 腾讯面试题——位图的应用
- 远程网站监控
- 洛谷 P1270 “访问”美术馆