@@ -0,0 +1,1280 @@
+/**%0A * Reverse a singly linked list.%0A *%0A * Hint:%0A *%0A * A linked list can be reversed either iteratively or recursively. Could you implement both?%0A *%0A * Tags: Linked List%0A * %0A * Similar Problems: (M) Reverse Linked List II, (M) Binary Tree Upside Down, (E) Palindrome Linked List%0A */%0Apublic class ReverseLinkedList %7B%0A%0A    /**%0A     * Recursive%0A     *%0A     * Divide the list into 2 parts - head and the rest starts from head.next%0A     * Reverse the rest of the linked list%0A     * Append head to the tail of reversed linked list%0A     * Return newHead of the reversed linked list%0A     */%0A    public ListNode reverseList(ListNode head) %7B%0A        if (head == null %7C%7C head.next == null) return head;%0A        ListNode newHead = reverseList(head.next);%0A        head.next.next = head;%0A        head.next = null;%0A        return newHead;%0A%0A    %7D%0A%0A    /**%0A     * Iterative%0A     */%0A    public ListNode reverseList2(ListNode head) %7B%0A        ListNode newHead = null;%0A        while (head != null) %7B%0A            ListNode next = head.next;%0A            head.next = newHead;%0A            newHead = head;%0A            head = next;%0A        %7D%0A        return newHead;%0A    %7D%0A%0A    public class ListNode %7B%0A%0A        int val;%0A        ListNode next;%0A%0A        ListNode(int x) %7B%0A            val = x;%0A        %7D%0A    %7D%0A%7D%0A

add 206 Reverse linked list