package com.fishercoder.solutions;

import com.fishercoder.common.classes.ListNode;

public class _206 {

    public static class Solution1 {
        public ListNode reverseList(ListNode head) {
            ListNode prev = null;
            ListNode curr = head;
            while (curr != null) {
                ListNode next = curr.next;
                curr.next = prev;
                prev = curr;
                curr = next;
            }
            return prev;
        }
    }

    public static class Solution2 {
        public ListNode reverseList(ListNode head) {
            return reverse(head, null);
        }

        ListNode reverse(ListNode head, ListNode newHead) {
            if (head == null) {
                return newHead;
            }
            ListNode next = head.next;
            head.next = newHead;
            newHead = head;
            head = next;
            return reverse(head, newHead);
        }
    }

}
@@ -209,20 +209,23 @@
 istNode 
-prev
+newHead
  = null;
@@ -241,53 +241,19 @@
     
-ListNode curr = head;%0A            while (curr
+while (head
  != 
@@ -292,20 +292,20 @@
  next = 
-curr
+head
 .next;%0A 
@@ -323,20 +323,20 @@
     
-curr
+head
 .next = 
 prev
@@ -331,20 +331,23 @@
 .next = 
-prev
+newHead
 ;%0A      
@@ -360,19 +360,22 @@
     
-prev = curr
+newHead = head
 ;%0A  
@@ -392,12 +392,12 @@
     
-curr
+head
  = n
@@ -438,12 +438,15 @@
 urn 
-prev
+newHead
 ;%0A  

refactor 206