371. Sum of Two Integers (实现二进制全加器)
来源:互联网 发布:mac能打的网游 编辑:程序博客网 时间:2024/06/06 03:38
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.
public class Solution { public int getSum(int a, int b) { int temp=1,prev=0,tempA,tempB,tempRes,result = 0;for(int i=0;i<32;i++){tempA = a&temp;tempB = b&temp;tempRes = tempA^tempB^prev;prev = ((tempA^tempB)&prev|tempA&tempB)<<1;result |= tempRes;temp<<=1;}return result; }}
0 0
- 371. Sum of Two Integers (实现二进制全加器)
- leetcode 371. Sum of Two Integers(不用+ -实现加法)
- (Leetcode)371. Sum of Two Integers
- 371. Sum of Two Integers(C++)
- 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
- android JNI native 编程
- Oracle中的pl/sql
- MyBatis-----4、MyBatis使用generator
- Code First Migrations更新数据库结构(数据迁移)
- Linux Python yum安装
- 371. Sum of Two Integers (实现二进制全加器)
- 关于emqtt使用的一些心得
- IE、FF CSS 兼容性、兼容浏览器的技巧
- iOS - 打电话、发短信、发邮件、打开网页
- RecyclerView
- linux环境变量
- HistCite 引文分析软件的利器
- PostgreSQL 某单机插入性能测试 1200万行/s, 4.2GB/s
- 提高axure设计效率的建议