Man, this problem looks simple from the name, but it nearly killed me. The idea is clear, but the implementation was painful. My fundamentals really need work – it took forever.
The problem says: given two non-negative linked lists, add the corresponding values of the two lists. If the sum is 10 or greater, there’s a carry – and the carry is what really tripped me up. Got WA once because of it.
One thing to note is that the numbers need to be reversed. I directly reversed both input linked lists, which led to AC. If you miss this, you’ll likely get wrong answers. But reversing a linked list really frustrated me – I need to practice my fundamentals more.
There’s also the issue of deep copy vs. shallow copy with pointers.
| |