Created
May 25, 2019 20:18
-
-
Save madhur/3546c5365c7cc03fcc7253718ff8850a to your computer and use it in GitHub Desktop.
Reverse 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
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