/**
 * Reverse a singly linked list.
 *
 * Hint:
 *
 * A linked list can be reversed either iteratively or recursively. Could you implement both?
 *
 * Tags: Linked List
 * 
 * Similar Problems: (M) Reverse Linked List II, (M) Binary Tree Upside Down, (E) Palindrome Linked List
 */
public class ReverseLinkedList {

    /**
     * Recursive
     *
     * Divide the list into 2 parts - head and the rest starts from head.next
     * Reverse the rest of the linked list
     * Append head to the tail of reversed linked list
     * Return newHead of the reversed linked list
     */
    public ListNode reverseList(ListNode head) {
        if (head == null || head.next == null) return head;
        ListNode newHead = reverseList(head.next);
        head.next.next = head;
        head.next = null;
        return newHead;

    }

    /**
     * Iterative
     */
    public ListNode reverseList2(ListNode head) {
        ListNode newHead = null;
        while (head != null) {
            ListNode next = head.next;
            head.next = newHead;
            newHead = head;
            head = next;
        }
        return newHead;
    }

    public class ListNode {

        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
        }
    }
}

@@ -1,43 +1,133 @@
-/**%0A * Reverse a singly linked list.%0A *
+package com.freetymekiyan.algorithms.level.easy;%0A%0A/**%0A * Reverse a singly linked list.%0A * %3Cp%3E%0A * click to show more hints.%0A * %3Cp%3E
 %0A * 
@@ -132,19 +132,16 @@
 * Hint:%0A
- *%0A
  * A lin
@@ -228,16 +228,138 @@
 both?%0A *
+ %3Cp%3E%0A * Company Tags: Uber, Facebook, Twitter, Zenefits, Amazon, Microsoft, Snapchat, Apple, Yahoo, Bloomberg, Yelp, Adobe
 %0A * Tags
@@ -376,12 +376,8 @@
 ist%0A
- * %0A
  * S
@@ -539,23 +539,28 @@
 ecursive
+.
 %0A     *
+ %3Cp%3E
 %0A     * 
@@ -629,16 +629,17 @@
 ead.next
+.
 %0A     * 
@@ -665,32 +665,33 @@
  the linked list
+.
 %0A     * Append h
@@ -725,24 +725,47 @@
  linked list
+, which is head's next.
 %0A     * Retu
@@ -802,16 +802,17 @@
 ked list
+.
 %0A     */
@@ -907,16 +907,46 @@
 == null)
+ %7B // 1 or no node%0A           
  return 
@@ -947,24 +947,34 @@
 eturn head;%0A
+        %7D%0A
         List
@@ -1093,17 +1093,16 @@
 ewHead;%0A
-%0A
     %7D%0A%0A 
@@ -1124,16 +1124,289 @@
 terative
+.%0A     * Create a new head.%0A     * Loop through the list.%0A     * For each node, get its next first.%0A     * Point itself to the previous head.%0A     * Move previous head to current node.%0A     * Then move to the next node and do the same thing.%0A     * Stop when reach the end.
 %0A     */

update Reverse Linked List