题解 | #反转链表#
反转链表
http://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca
头插法倒序
public class Solution { public ListNode ReverseList(ListNode head) { if(head==null||head.next==null)return head; ListNode newhead=new ListNode(-1); ListNode after=new ListNode(-1); while(head!=null){ after=head.next;//原来链表后续节点 ListNode node=newhead.next;//新链表头插 newhead.next=head;//头插 head.next=node;//头插 head=after; } return newhead.next; } }