2026-06-01 18:12:40 +08:00
|
|
|
#+ANKI_DECK: study_deck_02
|
2026-06-01 17:12:10 +08:00
|
|
|
* TODO 0371. Sum of Two Integers :medium:
|
2026-06-01 02:33:30 +08:00
|
|
|
:PROPERTIES:
|
2026-06-01 17:22:07 +08:00
|
|
|
:NEETCODE: [[file:../../roadmap.org::*0371. Sum of Two Integers][0371. Sum of Two Integers]]
|
2026-06-01 02:33:30 +08:00
|
|
|
:END:
|
|
|
|
|
|
2026-06-01 17:22:07 +08:00
|
|
|
Given two integers ~a~ and ~b~, return /the sum of the two integers without using the operators/ ~+~ /and/ ~-~.
|
|
|
|
|
|
|
|
|
|
*Example 1:*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#+begin_src
|
|
|
|
|
Input: a = 1, b = 2
|
|
|
|
|
Output: 3
|
|
|
|
|
#+end_src
|
|
|
|
|
*Example 2:*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#+begin_src
|
|
|
|
|
Input: a = 2, b = 3
|
|
|
|
|
Output: 5
|
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*Constraints:*
|
|
|
|
|
|
|
|
|
|
- ~-1000 <= a, b <= 1000~
|
|
|
|
|
|
2026-06-01 02:39:53 +08:00
|
|
|
** TODO Approach
|
|
|
|
|
Write your approach here.
|
|
|
|
|
|
|
|
|
|
** TODO Python
|
2026-06-05 22:32:49 +08:00
|
|
|
#+begin_src python :lc-problem 371 :lc-lang python3
|
2026-06-01 17:22:07 +08:00
|
|
|
class Solution:
|
|
|
|
|
def getSum(self, a: int, b: int) -> int:
|
2026-06-01 02:39:53 +08:00
|
|
|
#+end_src
|
|
|
|
|
|
|
|
|
|
** TODO C++
|
2026-06-05 22:32:49 +08:00
|
|
|
#+begin_src cpp :lc-problem 371
|
2026-06-01 17:22:07 +08:00
|
|
|
class Solution {
|
|
|
|
|
public:
|
|
|
|
|
int getSum(int a, int b) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
};
|
2026-06-01 02:33:30 +08:00
|
|
|
#+end_src
|