public ListNode ReverseList(ListNode head)
{
if (head == null)
{
return null;
}
ListNode pre = null;
ListNode next = null;
while (head != null)
{
next = head.next;
head.next = pre;
pre = head;
head = next;
}
return pre;
}
算法练习 (1)单链表反转
最新推荐文章于 2020-09-16 21:17:09 发布