learning
leetcode
https://leetcode.com/problems/add-two-numbers/
You are given two non-empty linked lists representing two 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.
Example:
Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 0 -> 8
Explanation: 342 + 465 = 807.
I didn't take care of zeros.
I will take take of zeros
I didn't convert l1 and l2 to numbers correctly, from the very beginning, QQQQ.
If l1 or l2 is null, it will be mapped to a zero.
I don't need a dummy head for the output, since I will have at least a digit from the sum of l1 and l2.
Runtime: 36 ms, faster than 99.97% of Python online submissions for Add Two Numbers.
Memory Usage: 11.8 MB, less than 74.88% of Python online submissions for Add Two Numbers.
Next challenges:
Multiply Strings
Add Binary
Sum of Two Integers
Add Strings
Add Two Numbers II
Add to Array-Form of Integer
Learn to run code.
This is incorrect.
I made a mistake of reversing the order of linked list
Java
Using a dummy head can avoid accessing a pointer with null address.
Python3
divmod
, Dummy Head