Last active
October 11, 2018 22:52
-
-
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.
This file contains hidden or 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
| 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