Skip to content

Instantly share code, notes, and snippets.

@lienista
Last active October 11, 2018 22:52
Show Gist options
  • Select an option

  • Save lienista/d8de39388462d65454a43e314417a1d3 to your computer and use it in GitHub Desktop.

Select an option

Save lienista/d8de39388462d65454a43e314417a1d3 to your computer and use it in GitHub Desktop.
(Algorithms in Javascript) Leetcode 206. Reverse Linked List - Reverse a singly linked list.
const reverseList = function(head) {
let previousNode = null;
let currentNode = head;
let nextNode = null;
while(currentNode) {
//reverse the pointers
nextNode = currentNode.next;
currentNode.next = previousNode;
//move list forward
previousNode = currentNode;
currentNode = nextNode;
}
return previousNode;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment