不使用运算符 + 和-,计算两整数a 、b之和。
示例:
若 a = 1 ,b = 2,返回 3。

详见:https://leetcode.com/problems/sum-of-two-integers/description/

C++:

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

参考:https://www.cnblogs.com/grandyang/p/5631814.html

371 Sum of Two Integers 两整数之和的更多相关文章

  1. [LeetCode] Sum of Two Integers 两数之和

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

  2. Java实现 LeetCode 371 两整数之和

    371. 两整数之和 不使用运算符 + 和 - ​​​​​​​,计算两整数 ​​​​​​​a .b ​​​​​​​之和. 示例 1: 输入: a = 1, b = 2 输出: 3 示例 2: 输入: ...

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

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

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

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

  5. leetcode python两整数之和

    # Leetcode 371 两整数之和***### 题目描述 **不使用**运算符 `+` 和 `-` ​​​​​​​,计算两整数 `​​​​​​​a `.`b` ​​​​​​​之和. **示例1: ...

  6. 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) { ...

  7. Leecode刷题之旅-C语言/python-349两整数之和

    /* * @lc app=leetcode.cn id=371 lang=c * * [371] 两整数之和 * * https://leetcode-cn.com/problems/sum-of-t ...

  8. C#求任意两整数之和

    2019.9.11 作业要求: 求出任意两整数之和 解决方案: using System; using System.Collections.Generic; using System.Linq; u ...

  9. [Swift]LeetCode371. 两整数之和 | 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. Avro kafka(Producer-Consumer)

    https://blog.csdn.net/mlljava1111/article/details/51376990

  2. python的for else语句

    Python循环中的else语句 绝大部分编程语言中都有条件判断语句,比如 if … else ,在大部语言中,else 一般只在条件判断语句中出现,与 if 语句配套出现,不过在 Python 中, ...

  3. webpack 输出多个文件

    http://react-china.org/t/webpack/1870/2 webpack 文章 entry = { "button": "demo/button/i ...

  4. 【CV论文阅读】Image Captioning 总结

    初次接触Captioning的问题,第一印象就是Andrej Karpathy好聪明.主要从他的两篇文章开始入门,<Deep Fragment Embeddings for Bidirectio ...

  5. [AngularJS 1.6] ngModelOptions and inheritance

    Problem with ngModleOptions before 1.6: <input type="text" name="fullname" ng ...

  6. 操作系统——IO管理

    一.IO系统结构 在计算机系统中.cpu要和很多外设进行交互.比方鼠标,键盘,网卡等等. 1.IO是怎样协调工作的那? (1)对于设备来说,其有两部分组成,一部分是机械部分,还有一部分是电子控制部分. ...

  7. 【block第四篇】实现

    -------------------------------------------欢迎查看block连载博客[专栏]--------------------------------------[b ...

  8. Android基础新手教程——4.1.1 Activity初学乍练

    Android基础新手教程--4.1.1 Activity初学乍练 标签(空格分隔): Android基础新手教程 本节引言: 本节開始解说Android的四大组件之中的一个的Activity(活动) ...

  9. qq xxs

    qq xxs qq xxs 有很多举个简单例子 : QQ空间发段文章 带上 <script> 提交(document.cookie) 到 自己服务端获取 </script> 在 ...

  10. Yaf的性能

    http://www.laruence.com/manual/yaf.bench.html 之前团队代码在ip的根下 http://192.168.6.212:83/js/common.js ; cd ...