首页 > 学院 > 开发设计 > 正文

371. Sum of Two Integers

2019-11-11 02:11:03
字体:
来源:转载
供稿:网友

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.

class Solution {public: int getSum(int a, int b) { if(b == 0) return a; int c = a ^ b; int carry = (a & b) << 1; return getSum(c, carry); }};
上一篇:C#抽象类总结

下一篇:活动选择问题

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表