Extra rep
Rep 1of 5 in this section
Foundation Rep~10 min
Weave two lists
a and b are the heads of two linked lists. Either may be None (an empty list). a is as long as b, or one node longer.
Write weave(a, b) that rewires the existing nodes so they alternate, starting with a: a1, b1, a2, b2, … Return the head (still the first node of a). No new nodes.
1 -> 2 -> 3 and 7 -> 8 → 1 -> 7 -> 2 -> 8 -> 3
Building toward LC 143 · Reorder List
Why this rep: block 1 of 5, weave two lists together.
Reminder
Same rule as reversing: before you overwrite a .next, keep what it pointed to in a variable.
main.pylearnPython