首页 > 其他 > 详细

371. Sum of Two Integers

时间:2020-04-24 18:14:15      阅读:45      评论:0      收藏:0      [点我收藏+]
package LeetCode_371

/**
 * 371. Sum of Two Integers
 * https://leetcode.com/problems/sum-of-two-integers/description/
 * https://www.polarxiong.com/archives/LeetCode-371-sum-of-two-integers.html
 * */
class Solution {
    fun getSum(a: Int, b: Int): Int {
        var carry = a and b
        var result = a xor b
        while (carry != 0) {
            val shiftCarry = carry shl 1
            carry = result and shiftCarry
            result = result xor shiftCarry
        }
        return result
    }
}

 

371. Sum of Two Integers

原文:https://www.cnblogs.com/johnnyzhao/p/12768969.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!