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.
That’s how the type of the nodes is defined, not how you would access the numbers. You won’t need that code unless you’re creating your own nodes for whatever reason.
But it does show you its structure, and if you know its structure then you can pick things out from it.
So there are six total digits, 2 linked lists, each list contains 3 digits. How would one access an individual digit from a list with just self.val? This would only allow you to access one digit per linked list.
Ok, so L1 and L2 are not references to the linked lists, they are references to individual nodes. I guess my only question is now is how do you reference a particular node if you cant index a linked list?
This video explains exactly how linked lists work with a notebook and pen without explaining the code behind it. This I understand. I’m just confused about traversal and the meaning of certain lables like ‘self.val’. Does self.val reference the first node in a list? or the list itself? Self.next reference the next node.
So if I have l1: (1-2-3) and l2: (4-5-6)
What does l1.val reference? 1? Or is there still something fundamental which I am missing?