Mark As Completed Discussion

One Pager Cheat Sheet

  • We can create a Linked List class to help us append and prepend nodes in O(1) time and space complexity.
  • The linked list requires a head and tail reference in order to use prepend and append methods.
  • We will append a new LinkedListNode to the list by setting the last node's next attribute to the new node, which will always be the next of the tail and the last node in the chain.
  • We can prepend new nodes to a Linked List by creating a new node and setting its next to the current head.
  • Translating this into code results in a boldly structured sentence.
  • We can achieve O(1) time and space complexity for both append() and prepend() by saving a reference to both the head and tail nodes.

This is our final solution.

To visualize the solution and step through the below code, click Visualize the Solution on the right-side menu or the VISUALIZE button in Interactive Mode.

JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

That's all we've got! Let's move on to the next tutorial.

If you had any problems with this tutorial, check out the main forum thread here.