Show problems as
Classic problem #2235EasyMath

Add Two Integers

Real-world version: Combine Two Stock Corrections
Tracked in this browser only
Read Add Two Integers on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A stock sheet records every correction to a line as one signed whole number: a positive value adds units to the line, a negative value removes them, and zero leaves the line where it was.

Two corrections have been filed against the same line, first and then second. Whoever filed them wants to replace both with a single correction that moves the line to exactly the same place.

Return that single correction.

Examples

Example 1

Input
first = 7, second = -3
Output
4

Adding 7 units and then removing 3 leaves the line 4 units above where it started.

Example 2

Input
first = -25, second = -40
Output
-65

Both corrections remove units, so the line ends up 65 units below where it started.

Example 3

Input
first = -100, second = 100
Output
0

The second correction undoes the first exactly, so the replacement correction is 0.

Example 4

Input
first = 0, second = 58
Output
58

The first correction leaves the line alone, so only the second one has any effect.

Constraints

  • -100 <= first, second <= 100

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def sum(first: int, second: int) -> int:
Java
public int sum(int first, int second)