Skip to content

Instantly share code, notes, and snippets.

@basekays
Created June 20, 2018 04:09
Show Gist options
  • Select an option

  • Save basekays/fe5f7320bf57994afdfa3ea460dcce42 to your computer and use it in GitHub Desktop.

Select an option

Save basekays/fe5f7320bf57994afdfa3ea460dcce42 to your computer and use it in GitHub Desktop.
/**
* 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