Skip to content

Instantly share code, notes, and snippets.

@HDegano
Last active August 29, 2015 14:20
Show Gist options
  • Save HDegano/7efb07f9809159f70958 to your computer and use it in GitHub Desktop.
Save HDegano/7efb07f9809159f70958 to your computer and use it in GitHub Desktop.
Reverse a Link List
public class Solution{
public ListNode ReverseLinkList(ListNode head){
if(head == null) return null;
ListNode current = head;
ListNode prev = null;
ListNode reverseHead = null;
while(current != null){
var currentNext = current.next;
if(currentNext == null)
reverseHead = current;
current.next = prev;
prev = current;
current = currentNext;
}
return reverseHead;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment