The TransCompilator

Solved LeetCode program · 2 of 1,000

#0002 · Add Two Numbers

Medium Math chunk-01.md

Original English source

The firstlist holds 2, 4, and 3, while the secondlist holds 5, 6, and 4. Start with an empty list for the answer, a carry of 0, and a position of 0. The firstlast is the last position of firstlist. The secondlast is the last position of secondlist.
Repeat while position is at most firstlast or position is at most secondlast or carry is 1.
The sum is carry. If position is at most firstlast, set sum to sum plus item position of firstlist. If position is at most secondlast, set sum to sum plus item position of secondlist. Place sum modulo 10 into answer. Set carry to sum divided by 10. Add 1 to position.

For each value in answer, show value.

Open in Playground Browse all 1,000 problems

Expected stdout

7
0
8