反转链表
public ListNode ReverseList(ListNode head) {
if (head == null)
return null;
ListNode dummy = new ListNode(-1);
ListNode second = null;
while (head != null) {
second = head.next;
head.next = dummy.next;
dummy.next = head;
head = second;
}
return dummy.next;
}
浙公网安备 33010602011771号