/* public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; } }*/ public class Solution { public ListNode ReverseList(ListNode head) { //通过递归做:将链表看成特殊二叉树 //截至条件:当为叶子节点或者是节点为空截至 if(head==null||head.next==null){ return head; } //先将head。next后面的全部逆置,返回头节点 ListNode newhead = ReverseList(head.next); //将当前节点添加到逆置后的链表后面,就是改变这两个节点的指向 head.next.next = head; head.next = null; return newhead; } }