不使用运算符 + 和-,计算两整数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. Jquery为DIV添加点击事件,Jquery为a标签超链接添加点击事件

    <div>1</div> <div>2</div> <div>3</div> <div>4</div> ...

  2. Codeforces Educational Round 21

    A =w= B qwq C wvw D(multiset) 题意: 有n(n<=1e5)个数,希望通过把一个位置y的数字放到位置x上这个操作,使得新序列的某个前缀和等于总和的一半,问这样的操作是 ...

  3. Windows系统下查看已共享的文件夹的方法

    电脑使用时间比较长,共享过好几次文件夹,现在想取消共享,但共享文件夹的路径隐藏得太深,要怎么样才能快速找到共享文件夹的实际路径呢?” “其实现在单位常见的方法都是用网上邻居的共享文件夹,共享的文件夹也 ...

  4. Unity3D游戏开发最佳实践20技巧(一)

    关于这些技巧这些技巧不可能适用于每一个项目. 这些是基于我的一些项目经验.项目团队的规模从3人到20人不等. 框架结构的可重用性.清晰程度是有代价的--团队的规模和项目的规模决定你要在这个上面付出多少 ...

  5. 数据结构 - 希尔排序(Shell&#39;s Sort) 具体解释 及 代码(C++)

    数据结构 - 希尔排序(Shell's Sort) 具体解释 及 代码(C++) 本文地址: http://blog.csdn.net/caroline_wendy/article/details/2 ...

  6. Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] C C Problem about Polyline 数学

                                                                           C. A Problem about Polyline   ...

  7. go1

    关键字: break default func interface select case defer go map struct chan else goto package switch cons ...

  8. 如何调试Node.js

    Debugging Node.js with Chrome DevTools https://nodejs.org/en/docs/guides/debugging-getting-started/ ...

  9. 【Codeforces】665E Beautiful Subarrays

    E. Beautiful Subarrays time limit per test: 3 seconds memory limit per test: 512 megabytes input: st ...

  10. luogu 1121 环状最大两段子段和

    题目大意: 一个序列看做一个环 选两段数使它们和最大 思路: 定义一个dp数组i j 0/1 表示前i个取了连续的j段 0/1表示取不取第i个 但是因为看做一个环 首尾相接的情况可以看做是选三段,其中 ...