Created
June 20, 2018 04:09
-
-
Save basekays/fe5f7320bf57994afdfa3ea460dcce42 to your computer and use it in GitHub Desktop.
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
| /** | |
| * Definition for singly-linked list. | |
| * function ListNode(val) { | |
| * this.val = val; | |
| * this.next = null; | |
| * } | |
| */ | |
| /** | |
| * @param {ListNode} head | |
| * @return {ListNode} | |
| */ | |
| var reverseList = function(head) { | |
| var previousNode = null; | |
| while (head) { | |
| var nextNode = head.next; | |
| head.next = previousNode; | |
| previousNode = head; | |
| head = nextNode; | |
| } | |
| return previousNode; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment