Leetcode Problem 707. Design Linked List

707. Design Linked List

Leetcode Solutions

Singly Linked List Implementation

  1. Define a ListNode class with val and next.
  2. Initialize MyLinkedList with a sentinel node.
  3. Implement get to traverse the list until the index.
  4. Implement addAtHead by creating a new node and linking it to the current head.
  5. Implement addAtTail by traversing to the end and linking the new node.
  6. Implement addAtIndex by finding the node before the index and linking the new node.
  7. Implement deleteAtIndex by linking the node before the index to the node after the index.
UML Thumbnail

Doubly Linked List Implementation

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...