[劍指offer] JAVA版題解 面試題65

在這裏插入圖片描述

代碼演示:

package swordfingeroffer;

/**
 * <p>Description: </p>
 *
 * @author 羅志遠
 * @version 1.0
 * @name InterviewQuestion65
 * @date 2020-07-05 21:10
 */
public class InterviewQuestion65 {
    public int addTwoNumber(int num1, int num2) {
        while (0 != num2) {
            int curSum = num1 ^ num2;
            int carry = (num1 & num2) << 1;
            num1 = curSum;
            num2 = carry;
        }
        return num1;
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章