public static ListNode reverseList(ListNode head) { if(head.next == null || head == null){ return head; }else{ ListNode node = reverseList(head.next); //这里反转使用head,而不是node, //node 只是用来返回 //置反 head.next.next = head; //去掉原来的指针 head.next = null; return node; } }
|
近期评论