File tree 2 files changed +25
-0
lines changed
2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 154
154
349|[ Intersection of Two Arrays] ( ./0349-intersection-of-two-arrays.js ) |Easy|
155
155
350|[ Intersection of Two Arrays II] ( ./0350-intersection-of-two-arrays-ii.js ) |Easy|
156
156
367|[ Valid Perfect Square] ( ./0367-valid-perfect-square.js ) |Easy|
157
+ 371|[ Sum of Two Integers] ( ./0371-sum-of-two-integers.js ) |Medium|
157
158
374|[ Guess Number Higher or Lower] ( ./0374-guess-number-higher-or-lower.js ) |Medium|
158
159
383|[ Ransom Note] ( ./0383-ransom-note.js ) |Easy|
159
160
387|[ First Unique Character in a String] ( ./0387-first-unique-character-in-a-string.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments