Leetcode 371: Sum of Two Integers

Input: a = 1, b = 2
Output: 3
Input: a = 2, b = 3
Output: 5
  • -1000 <= a, b <= 1000
class Solution {
public:
int getSum(int a, int b) {
int sum = a;
while (b != 0) {
sum = a ^ b;
b = (a & b) << 1;
a = sum;
}
return sum;
}
};

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

[DPS909] Refactoring My SSG Code

Amazing list of Ruby projects you can build!

Vulnhub’s Bravery…

Stimulsoft Reports 2018.2.3 released

A guide to InfluxDB

How To Add Awesome Monokai Colors For Beautiful C# Development in Visual Studio 2017

Handling Web Gestures in Flutter

What is Zenity, Espeak-ng and Date keywords in Linux also get to know some playful commands.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
dume0011

dume0011

More from Medium

“Exchange Argument” is a cool idea :)

MCLT — More Code Less Talk

The pandemic of Data Structures and Algorithms Courses

[Leet Code] Maximum Number of Words Found in Sentences

Data Structures: Traversing, Insertion & Deletion