206 Reverse Linked List
Given the head of a singly linked list, reverse the list, and return the reversed list.
头插法
class Solution {
public ListNode reverseList(ListNode head) {
ListNode h = new ListNode();
ListNode t;
while(head != null){
t=head.next;
head.next=h.next;
h.next=head;
head=t;
}
return h.next;
}
}