LeetCode371——Sum of Two Integers(不用+)

来源:互联网 发布:网站授权码系统源码 编辑:程序博客网 时间:2024/06/15 19:38


class Solution {public:    int getSum(int a, int b) {        int sum = a;                while (b != 0)        {            sum = a ^ b;//calculate sum of a and b without thinking the carry             b = (a & b) << 1;//calculate the carry            a = sum;//add sum(without carry) and carry        }                return sum;    }};


原创粉丝点击