+ 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)
6 odpowiedzi
+ 6
here is my code in Python 🐍
try it!
https://code.sololearn.com/c5S86lUrTi8z/?ref=app
+ 5
Read the #3 line in question @Martin
+ 5
+ 4
I don't get the second and third output
Edit: Ok, thanks ;)
+ 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