/*
public class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}*/
public class Solution {
    private ListNode newHead;
    public ListNode ReverseList(ListNode head) {
        ReverseList(null, head);
        return newHead;
    }

    //翻转指定链表
    private void ReverseList(ListNode xFrom, ListNode x) {
        if (x == null) {
            //如果x为空,则x的前一个结点,即xFrom为新链表的头部
            newHead = xFrom;
            return;
        }

        //把大问题转换为小问题
        ReverseList(x, x.next);
        x.next = xFrom;
    }
}