Skip to content

Instantly share code, notes, and snippets.

@gabhi
Last active August 29, 2015 13:58
Show Gist options
  • Save gabhi/9985846 to your computer and use it in GitHub Desktop.
Save gabhi/9985846 to your computer and use it in GitHub Desktop.
reverse linked list
private static ListNode reverseList(ListNode head) {
ListNode current = head;
if (current == null)
return null;
if (current.next == null)
return current;
ListNode nextItem = current.next;
current.next = null;
ListNode remaining = reverseList(nextItem);
nextItem.next = current;
return remaining;
}
class ListNode {
public int value;
public ListNode next;
public ListNode(int value) {
this.value = value;
this.next = null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment