Created
February 15, 2024 18:22
-
-
Save LenarBad/f94a41363de085442af879438016c459 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) { | |
ListNode prev = null; | |
ListNode current = head; | |
while(current != null) { | |
ListNode next = current.next; | |
current.next = prev; | |
prev = current; | |
current = next; | |
} | |
return prev; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment