输入一个链表,反转链表后,输出新链表的表头。
public class Solution {
public ListNode ReverseList(ListNode head) {
ListNode pHead=head;
if(head==null)
return null;
ListNode second=pHead.next;
ListNode three=null;
pHead.next=null;
while(second!=null){
three=second.next;
second.next=pHead;
pHead=second;
second=three;
}
return pHead;
}
}