Last active
November 9, 2018 17:44
-
-
Save anish000kumar/14287c7aecf8aac6bd053b528a064e17 to your computer and use it in GitHub Desktop.
reverse a linked list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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