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