15 · Linked Lists

#2 Add Two Numbers

Mediumsolve on LeetCode ↗

frequently reported atAdobeBloombergMicrosoftAmazonGoogleMeta

the problem

In plain words

Two non-negative integers are stored as linked lists of digits in reverse order (ones digit first). Return their sum as a list in the same format.

in l1 = [2,4,3], l2 = [5,6,4]

out [7,0,8]

342 + 465 = 807.

in l1 = [0], l2 = [0]

out [0]

in l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]

out [8,9,9,9,0,0,0,1]

  • 1 ≤ nodes in each list ≤ 100
  • 0 ≤ Node.val ≤ 9
  • No leading zeros except the number 0 itself

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

LeetCode-style: complete the class. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #66
      Plus One
      Easyin Math & Numbers
    2. #43
      Multiply Strings
      Mediumin Math & Numbers
    3. #371
      Sum of Two Integers
      Mediumin Bits