给你单链表的头节点 head
,请你反转链表,并返回反转后的链表。
class Solution {
public ListNode reverseList(ListNode head) {
if(head == null) return null ;
ListNode a = head;
ListNode b = a.next;
a.next = null;
while(b!=null){
ListNode c = b.next;
b.next = a;
a = b;
b = c;
}
head = a;
return head;
}
}