The Algorithms logo
The Algorithms

Reverse Singly Linked List

/** A LinkedList based solution to reverse a number
Problem Statement: Given a number such that each of its digit is stored in a singly linked list. Reverse the linked list and return the head of the linked list Link for the Problem: */
class ReverseSinglyLinkedList {
  solution (head) {
    let prev = null
    let next = null
    while (head) {
      next = = prev
      prev = head
      head = next
    return prev
export { ReverseSinglyLinkedList }