Where it runs
1. The problem
An array lets you read any item at once by its position number (its index). Inserting in the middle is costly, though: everything after the insertion point has to shift one cell along. A linked list works the other way round. You can't read an item by its number at once, but you can insert or cut out an item in one step, as long as you already stand next to that place.
An array stores its values in one solid block of memory, one after another. So reading position 5 is instant, while inserting at the front is costly: every later item has to shift. A linked list stores each value in a separate node. A node holds the value itself and a link to the next node, and so the nodes form a chain. Adding an item at the front is instant. Jumping to position 5 is impossible, though: you have to walk there along the chain.
Later lessons have harder tricks: reversing a list, finding a loop in it, merging two lists. For those you first need the simple part: build a chain, walk along it, and read values from it. That is what this lesson does.
This step is part of the paid track
The first 33 steps are open to everyone: lesson, exercise and tests. This one opens with full access. Start with a free account and the free steps.
Create a free accountSee what is includedOn LeetCode
Problems that hand you the head of a linked list and ask you to walk it, to read every value, collect the values, or build a new list as you go.
Walk from head to null, doubling the number and adding each bit.
Walk the list once with the values of nums in a Set, and count the places where a run of matching nodes starts.
Walk the list, add up the values between two zeros, and append each sum to a new list.