Skip to content

Instantly share code, notes, and snippets.

@orhanobut
Created April 22, 2015 20:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orhanobut/de19bcbb9524042d184e to your computer and use it in GitHub Desktop.
Save orhanobut/de19bcbb9524042d184e to your computer and use it in GitHub Desktop.
Reverse singly list in place
public static Node reverse(Node root){
if (root == null) return null;
Node p = null;
Node n = root;
while (n != null){
Node t = n.next;
n.next = p;
p = n;
n = t;
}
return p;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment