371. Sum of Two Integers

    xiaoxiao2023-03-24  4

    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; }为什么自己测试这个函数结果会不对呢??

    转载请注明原文地址: https://ju.6miu.com/read-1201989.html
    最新回复(0)