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.

题目要求:计算两个整型的和,但是不能用+和-

我们知道a+b为((a&b)<<1)+(a^b),因此可以用递归的方法

class Solution {
public:
int getSum(int a, int b) {
if (a == )return b;
if (b == )return a;
return getSum((a&b)<<,a^b);
}
};

LeetCode 371. Sum of Two Integers的更多相关文章

  1. 剑指offer 65. 不用加减乘除做加法(Leetcode 371. Sum of Two Integers)

    剑指offer 65. 不用加减乘除做加法(Leetcode 371. Sum of Two Integers) https://leetcode.com/problems/sum-of-two-in ...

  2. LeetCode 371. Sum of Two Integers (两数之和)

    Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...

  3. Leetcode 371: Sum of Two Integers(使用位运算实现)

    题目是:Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. ...

  4. LeetCode: 371 Sum of Two Integers(easy)

    题目: Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. ...

  5. LeetCode Javascript实现 344. Reverse String 292. Nim Game 371. Sum of Two Integers

    344. Reverse String /** * @param {string} s * @return {string} */ var reverseString = function(s) { ...

  6. 通过位运算求两个数的和(求解leetcode:371. Sum of Two Integers)

    昨天在leetcode做题的时候做到了371,原题是这样的: 371. Sum of Two Integers Calculate the sum of two integers a and b, b ...

  7. 【一天一道LeetCode】#371. Sum of Two Integers

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Calcula ...

  8. 【LeetCode】371. Sum of Two Integers 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 位运算 日期 题目地址:https://leetco ...

  9. [LeetCode&Python] Problem 371. Sum of Two Integers

    Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...

随机推荐

  1. 分布式系统(Distributed System)资料

    这个资料关于分布式系统资料,作者写的太好了.拿过来以备用 网址:https://github.com/ty4z2008/Qix/blob/master/ds.md 希望转载的朋友,你可以不用联系我.但 ...

  2. Sep19_html/css_imooc学习笔记_1

    1. <h1></h1>标题,h1-h6从大到小 2. <p></p> 段落 3. <img src=“1.jpg”> 加入图片 4.基本结 ...

  3. Option

    在scala中Option是一个有可能包含值的容器 Option对应的特质如下 trait Option[T] { def isDefined: Boolean def get: T def getO ...

  4. groupspecWidhoutAuthorizations与groupspecWidthAuthorizations的区别

    GroupSpecifier是一个用来定义group所有参数的类.首先,将它命名为“myGroup/g1”.然后设置 serverChannel与Stratus进行沟通.最后发布.这样,我们就完成了P ...

  5. java异常知识点整理

    异常处理机制:捕获异常(try-catch-finally)和声明抛弃异常(throw); 所有的异常类都直接或者间接地继承于Throwable类: java异常分为可查异常和不可查异常两种.可查异常 ...

  6. ajax处理的方式

    1.方式一:在一个web页面中 [System.Web.Services.WebMethod],有点象webservers的方法! 前台: 返回的数据: msg:Object {d: "He ...

  7. quartz(1)

    关于定时任务的操作方法,java语言本身具有 Timer 来解决,但Timer 作用起来不是特别的舒服,由于项目的需要,使用了Quartz 这个调度框架,现把学习过程记录下来,方便以后查阅. 本教程是 ...

  8. ubuntu 配置vim(vimrc)

    打开终端:ctrl+alt+t 进入vim文件:cd /etc/vim 打开vimrc文件:sudo gedit vimrc 然后在行末if语句前加上下面的内容,"  这个符号为注释,后面内 ...

  9. LeetCode-Search in Rotated Sorted Array II

    Follow up for "Search in Rotated Sorted Array": What if duplicates are allowed? Would this ...

  10. DDoS

    Distributed Denial of Service (DDoS) Attacks/tools https://staff.washington.edu/dittrich/misc/ddos/ ...