Skip to content

Instantly share code, notes, and snippets.

@LenarBad
Created February 15, 2024 18:22
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 LenarBad/f94a41363de085442af879438016c459 to your computer and use it in GitHub Desktop.
Save LenarBad/f94a41363de085442af879438016c459 to your computer and use it in GitHub Desktop.
Reverse linked list
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