Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd7d92d7

Browse files
committed
add: Sum of Two Integers
1 parent4f4f837 commitd7d92d7

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ This is the solutions collection of my LeetCode submissions, most of them are pr
4444
|307|[Range Sum Query - Mutable](https://leetcode.com/problems/range-sum-query-mutable/)|[JavaScript](./src/range-sum-query-mutable/res.js)|Medium|
4545
|342|[Power of Four](https://leetcode.com/problems/power-of-four/)|[JavaScript](./src/power-of-four/res.js)|Easy|
4646
|344|[Reverse String](https://leetcode.com/problems/reverse-string/)|[JavaScript](./src/reverse-string/res.js)|Easy|
47+
|371|[Sum of Two Integers](https://leetcode.com/problems/sum-of-two-integers/)|[JavaScript](./src/sum-of-two-integers/res.js)|Easy|
4748
|384|[Shuffle an Array](https://leetcode.com/problems/shuffle-an-array/)|[JavaScript](./src/shuffle-an-array/res.js)|Medium|
4849
|404|[Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves/)|[JavaScript](./src/sum-of-left-leaves/res.js)|Easy|
4950
|434|[Number of Segments in a String](https://leetcode.com/problems/number-of-segments-in-a-string/)|[JavaScript](./src/number-of-segments-in-a-string/res.js)|Easy|

‎src/sum-of-two-integers/res.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* res.js
3+
*@authors Joe Jiang (hijiangtao@gmail.com)
4+
*@date 2017-03-03 22:05:30
5+
*
6+
* Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.
7+
*
8+
* Example
9+
*
10+
* Given a = 1 and b = 2, return 3.
11+
*
12+
*@param {number} a
13+
*@param {number} b
14+
*@return {number}
15+
*/
16+
letgetSum=function(a,b){
17+
if(b===0){
18+
returna;
19+
}
20+
21+
while(b!==0){
22+
lett=a^b;
23+
b=(a&b)<<1;
24+
a=t;
25+
}
26+
27+
returna;
28+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp