剑指offer(48)不用加减乘除做加法

public class Solution {
    public int Add(int num1,int num2) {
        if(num1 == 0 && num2 == 0){
            return 0;
        }
        int temp = num1 ^ num2;//不进位
        int tempS = (num1 & num2) << 1;//进位
        if(tempS == 0){
            return temp;
        }else{
            //return temp + tempS;

              return Add(temp  + tempS);
        }
    }
}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务