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. Linux自己安装redis扩展

    注意:目录的权限   chomd 777 -R 注意:下面涉及的目录只是我自己安装的目录,要找自己对应的目录文件 1.安装redis 下载:https://github.com/nicolasff/p ...

  2. Installshield如何实现升级覆盖文件

    这个简单的问题,问过的人不计其数,但是反馈者寥寥,并且往往不能顺利达成目标,只能采取复杂方式来实现,这里吐槽一下IS的帮助文档,很庞大很全,但是有些小技巧就是不讲. 网友冰雪孤独哥今天提供了及时的反馈 ...

  3. gulp监听文件变化,并拷贝到指定目录

    暂时不支持目录修改.创建.删除var gulp = require('gulp'); var fs = require('fs'); var path = require('path'); var l ...

  4. 关于HTML页面布局要注意的问题

    1.用百分比设定元素宽度可能造成的错误 很多同学习惯使用百分比来设定页面元素(例如div,以下称作盒子,方便介绍)的宽度,这样做可能造成未知的错误,最常见的就是当页面被缩小,或者屏幕分辨率降低时,由于 ...

  5. <a>标签的用法。

    1.创建电子邮件链接: <html> <head> <title>发给朱永成</title> </head> <body> &l ...

  6. iOS页面传值-wang

    iOS页面间传值的方式(NSUserDefault/Delegate/NSNotification/Block/单例) 实现了以下iOS页面间传值:1.委托delegate方式:2.通知notific ...

  7. PS中的图像知识

    图像处理对于前端工作来说是一个不能回避的问题,ps技术也是我们必备的技能.用法可以在使用中不断的熟练,但针对前端技术本身的一些知识点,需要我们平时不断的积累才能够在使用中不出现问题. 如今的办公,已经 ...

  8. Linear Algebra Lecture5 note

    Section 2.7     PA=LU and Section 3.1   Vector Spaces and Subspaces   Transpose(转置) example: 特殊情况,对称 ...

  9. [NOIP2014]寻找道路(图论)

    题目描述 在有向图G 中,每条边的长度均为1 ,现给定起点和终点,请你在图中找一条从起点到终点的路径,该路径满足以下条件: 1 .路径上的所有点的出边所指向的点都直接或间接与终点连通. 2 .在满足条 ...

  10. 如何搭建 node,react 开发环境

    项目相关内容:Sublime + Node + React --注意:在 windows 操作系统中,如果把 node 安装在系统盘(一般是C盘),会导致 node 没有操作文件的权限的问题,如无法新 ...