package com.fishercoder.solutions;

import com.fishercoder.common.classes.ListNode;

/**
 * 206. Reverse Linked List
 *
 * Reverse a singly linked list.
 *
 * Example:
 * Input: 1->2->3->4->5->NULL
 * Output: 5->4->3->2->1->NULL
 *
 * Follow up:
 * A linked list can be reversed either iteratively or recursively. Could you implement both?
 * */
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);
        }
    }

}
@@ -82,269 +82,8 @@
 e;%0A%0A
-/**%0A * 206. Reverse Linked List%0A *%0A * Reverse a singly linked list.%0A *%0A * Example:%0A * Input: 1-%3E2-%3E3-%3E4-%3E5-%3ENULL%0A * Output: 5-%3E4-%3E3-%3E2-%3E1-%3ENULL%0A *%0A * Follow up:%0A * A linked list can be reversed either iteratively or recursively. Could you implement both?%0A * */%0A
 publ

refactor 206