Skip to content

Instantly share code, notes, and snippets.

@anish000kumar
Last active November 9, 2018 17:44
Show Gist options
  • Save anish000kumar/14287c7aecf8aac6bd053b528a064e17 to your computer and use it in GitHub Desktop.
Save anish000kumar/14287c7aecf8aac6bd053b528a064e17 to your computer and use it in GitHub Desktop.
reverse a linked list
function reverseLinkedList(head){
let prev = null;
let next = null;
while(head){
next = head.next;
head.next = prev;
prev = head;
head = next;
}
return prev;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment