Home | Projects | Notes > Problem Solving > LC - E - 2. Add Two Numbers

LC - E - 2. Add Two Numbers

 

Solutions in C++

Solution 1

When adding two one-digit numbers:

Complexity Analysis:

Solution:

 

Solution 2

My first solution. There are lots of redundancies in the code which could have been eliminated by using a dummy node as is described in the Solution 1.

Complexity Analysis:

Solution:

 

Solution 3

This solution uses recursion. One drawback of this solution is that if the size of two lists differ, extra memory consumption occurs to create nodes dynamically. Just note the idea of applying recursion.

Complexity Analysis:

Solution: