Skip to content

Instantly share code, notes, and snippets.

@charlespunk
Last active December 13, 2015 19:18
Show Gist options
  • Save charlespunk/4961675 to your computer and use it in GitHub Desktop.
Save charlespunk/4961675 to your computer and use it in GitHub Desktop.
//reverse singly linked list
public static Node reverseList(Node root){
if(root == null) return null;
return reverseListHelp(root);
}
public static Node reverseListHelp(Node root){
if(root.next == null) return root;
Node end = reverseListHelp(root.next);
root.next.next = root;
root.next = null;
return end;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment