371. Sum of Two Integers

来源:互联网 发布:淘宝秒杀流程 编辑:程序博客网 时间:2024/05/06 20:36

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.

int getSum(int a, int b) {    int result = a ^ b;    int carry = (a & b) << 1;    if (carry) return getSum(result, carry);    return result;}
为什么自己测试这个函数结果会不对呢??

0 0
原创粉丝点击