Skip to content

Commit 22803b3

Browse files
committed
Add solution #371
1 parent 25b8e1c commit 22803b3

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
349|[Intersection of Two Arrays](./0349-intersection-of-two-arrays.js)|Easy|
155155
350|[Intersection of Two Arrays II](./0350-intersection-of-two-arrays-ii.js)|Easy|
156156
367|[Valid Perfect Square](./0367-valid-perfect-square.js)|Easy|
157+
371|[Sum of Two Integers](./0371-sum-of-two-integers.js)|Medium|
157158
374|[Guess Number Higher or Lower](./0374-guess-number-higher-or-lower.js)|Medium|
158159
383|[Ransom Note](./0383-ransom-note.js)|Easy|
159160
387|[First Unique Character in a String](./0387-first-unique-character-in-a-string.js)|Easy|

Diff for: solutions/0371-sum-of-two-integers.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* 371. Sum of Two Integers
3+
* https://leetcode.com/problems/sum-of-two-integers/
4+
* Difficulty: Medium
5+
*
6+
* Given two integers a and b, return the sum of the two integers
7+
* without using the operators + and -.
8+
*/
9+
10+
/**
11+
* @param {number} a
12+
* @param {number} b
13+
* @return {number}
14+
*/
15+
var getSum = function(a, b) {
16+
const sum = a ^ b;
17+
const carry = (a & b) << 1;
18+
19+
if (!carry) {
20+
return sum;
21+
}
22+
23+
return getSum(sum, carry);
24+
};

0 commit comments

Comments
 (0)