Last active
December 13, 2015 19:18
-
-
Save charlespunk/4961675 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
//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