Skip to content

Add two numbers ​

Add two numbers — LeetCode

Two numbers are stored as linked lists with their digits in reverse order. Add them and return the sum as a linked list.

Approach ​

Can do the whole addition in one while loop. If l1 or l2 is not null or carry > 0, do a sum and keep on adding. Make sure to do null checks anytime l1 or l2 is accessed.

Remarks ​