Add Two Numbers - Sum of Two Linked List Numbers - aloalgo

Add Two Numbers - Sum of Two Linked List Numbers

Medium

You are given two non-empty linked lists, l1 and l2, where each represents a non-negative integer with its digits stored in reverse order (e.g., the number 342 is represented as 2 -> 4 -> 3).

Your task is to add the two numbers represented by l1 and l2 and return their sum as a new linked list, with its digits also stored in reverse order.

You may assume that:

  • Each node in the input linked lists contains a single digit.
  • The input linked lists will not have any leading zeros, with the sole exception being the number 0 itself (which is represented by a single node containing 0).

Return the head of the new linked list representing the sum.

Example 1

Inputs
l1 = 1 → null
l2 = 1 → null
Output
2 → null
Explanation:

This represents 1 + 1 = 2. The sum is represented as [2].

Example 2

Inputs
l1 = 2 → null
l2 = 8 → 9 → null
Output
0 → 0 → 1 → null
Explanation:

This represents 2 + 98 = 100. The sum is represented as [0, 0, 1].

Loading...
Inputs
l1 = 1 → null
l2 = 1 → null
Output
2 → null

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!