↓Skip to main content
  1. LeetCode/

LeetCode 2235: Add Two Integers

·1 min· ·
LeetCode Easy Math
Wei Yi Chung
Author
Wei Yi Chung
Working at the contributing of open source, distributed systems, and data engineering.
Table of Contents

Meta Data
#

Difficulty: easy First Attempt: 2025-12-17

  • Submissions: Accepted (Python) → Compile Error (C++) → Accepted (C++)

Approach
#

Return num1 + num2. I used this one to practice C++ syntax.

My Attempts
#

The first C++ version, return num1 + num2, was missing a semicolon: Compile Error.

Solution
#

class Solution:
    def sum(self, num1: int, num2: int) -> int:
        return num1 + num2

Complexity
#

Time O(1), space O(1).

Mistakes to Avoid
#

  • Switching from Python to C++, statements need a trailing semicolon.

Interview Explanation
#

Return the sum directly. The value range is tiny, so there is no overflow. Time O(1).

Related

LeetCode 2413: Smallest Even Multiple
·1 min
LeetCode Easy Math Number-Theory
LeetCode 2413 note: lcm(2, n), which is n when n is even and 2n when odd
LeetCode 1304: Find N Unique Integers Sum up to Zero
·1 min
LeetCode Easy Math Array
LeetCode 1304 note: place 1..n/2 and their negatives so each pair cancels, adding 0 when n is odd
LeetCode 3622: Check Divisibility by Digit Sum and Product
·1 min
LeetCode Easy Math
LeetCode 3622 note: compute the digit sum and product and test n % (sum + product) == 0, keeping the modulo the right way around
LeetCode 3536: Maximum Product of Two Digits
·2 mins
LeetCode Easy Math Sorting
LeetCode 3536 note: multiply the largest and second-largest digits; when a new maximum appears, the old maximum must move to second place
LeetCode 3492: Maximum Containers on a Ship
·1 min
LeetCode Easy Math
LeetCode 3492 note: at most n² cells and at most maxWeight // w by weight, so take the smaller, using integer division
LeetCode 1103: Distribute Candies to People
·1 min
LeetCode Easy Math Simulation
LeetCode 1103 note: simulate the rounds, giving i + 1 candies on the i-th turn, and hand all the rest to the current person when short