public static ListNode reverseList(ListNode head) {
if(head == null)
return null;
//前一个结点
ListNode pre = null;
//后节点
ListNode next = null;
//head 当前节点
while (head != null){
next = head.next;
//当前节点指向前一个节点
head.next = pre;
//指针前移
pre = head;
//指针前移
head = next;
}
return pre;
}
链表反转
最新推荐文章于 2024-06-19 22:17:16 发布