+ 13

Challenge: Add two numbers in Linked List

You are given two non-empty linked lists representing non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 itself. Input: (2, 4, 3) + (5, 6, 4) Output: (7, 0, 8) Input: (3, 6) + (1, 7, 5) Output: (4, 3, 6) Input: (5) + (5) Output: (0, 1)

1st Oct 2017, 5:45 AM
Kartikey Sahu
Kartikey Sahu - avatar
6 Answers
+ 6
here is my code in Python 🐍 try it! https://code.sololearn.com/c5S86lUrTi8z/?ref=app
1st Oct 2017, 7:18 AM
m abrate
m abrate - avatar
+ 5
Read the #3 line in question @Martin
1st Oct 2017, 6:04 AM
Kartikey Sahu
Kartikey Sahu - avatar
1st Oct 2017, 6:34 AM
Martin Möhle
Martin Möhle - avatar
+ 4
I don't get the second and third output Edit: Ok, thanks ;)
1st Oct 2017, 5:53 AM
Martin Möhle
Martin Möhle - avatar
+ 4
@Martin (3,6) + (1,7,5) both are in reverse order so true order is (6, 3) + (5, 7, 1) now adding them will be ( 6, 3, 4) and its reverse is (4, 3, 6) as we have to show in reverse. (5) + (5) is (1,0) in reverse (0, 1) as I said one node can have one digit only
1st Oct 2017, 5:58 AM
Kartikey Sahu
Kartikey Sahu - avatar