Easy-19

xiaoxiao2021-02-27  661

leetcode

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.

AC:

int getSum(int a, int b) {     int result;     while(b!=0)     {         result=a^b;         b=(a&b)<<1;         a=result;     }     return a; }

tips: 简单易懂的解法,很受益。

转载请注明原文地址: https://www.6miu.com/read-1089.html

最新回复(0)