Created
July 17, 2021 14:24
-
-
Save wohhie/2cea8721b55d37634d347d8a681eef32 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
public static SinglyLinkedListNode reverse(SinglyLinkedListNode llist) { | |
// Write your code here | |
SinglyLinkedListNode curr = llist; | |
SinglyLinkedListNode next = llist.next; | |
llist.next = null; // 1->null | |
while(next != null){ | |
SinglyLinkedListNode temp = next.next; // 3->4->5 | |
next.next = curr; // 2->1->null | |
curr = next; // 2->1->null; | |
next = temp; | |
} | |
return curr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment