不使用运算符 + 和-,计算两整数a 、b之和。
示例:
若 a = 1 ,b = 2,返回 3。

详见:https://leetcode.com/problems/sum-of-two-integers/description/

C++:

class Solution {
public:
    int getSum(int a, int b) {
        while(b)
        {
            int tmp=a^b;
            b=(a&b)<<1;
            a=tmp;
        }
        return a;
    }
};

 参考:https://www.cnblogs.com/grandyang/p/5631814.html

相关文章:

  • 2021-08-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-22
  • 2022-02-06
猜你喜欢
  • 2021-06-24
  • 2022-12-23
  • 2021-11-06
  • 2021-12-30
相关资源
相似解决方案