题目描述:
Reverse a singly linked list.
很简单,必须一次ac。
public ListNode reverseList(ListNode head) {
if(head==null){
return null;
}
ListNode last=head;
while(last.next!=null){
last=last.next;
}
while(head!=last){
ListNode next=head.next;
head.next=last.next;
last.next=head;
head=next;
}
return head;
}