Step 1 of 4
Node Pointers & Boundary Insertion
Start by implementing append(val) and prepend(val).
- When the list is empty (
this.head === null), bothheadandtailpoint to the newly createdListNode. append(val): Attach the new node tothis.tail.nextand updatethis.tailin $O(1)$ time.prepend(val): Pointnode.nexttothis.headand updatethis.headin $O(1)$ time.- Increment
this.length.
Your build
Running is free — Submit is what records the step. Or press ⌘↩
Tests
1 case| call | type | expected | result |
|---|---|---|---|
| runOps([["append",10],["append",20],["prepend",5],["toArray"],["size"]]) | appends and prepends nodes | [null,null,null,[5,10,20],3] | — |
Hints
Stuck? Hints open one at a time, each giving a little more away.
2 hints left