Skip to content

Instantly share code, notes, and snippets.

@madhur
Created May 25, 2019 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madhur/3546c5365c7cc03fcc7253718ff8850a to your computer and use it in GitHub Desktop.
Save madhur/3546c5365c7cc03fcc7253718ff8850a to your computer and use it in GitHub Desktop.
Reverse linked list
public ListNode reverseList(ListNode head) {
// Add your code below this line. Do not modify any other code.
ListNode currentNode = head;
ListNode previousNode= null;
while(currentNode != null)
{
ListNode nextNode = currentNode.next;
currentNode.next = previousNode;
previousNode = currentNode;
currentNode = nextNode;
}
return previousNode;
// Add your code above this line. Do not modify any other code.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment