Last active
August 29, 2015 14:20
-
-
Save HDegano/7efb07f9809159f70958 to your computer and use it in GitHub Desktop.
Reverse a Link List
This file contains 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
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