在面试中经常会被问到,如何进行【链表的反转】,
力扣网关联题目链接:
https://leetcode-cn.com/problemset/all/?search=%E5%8F%8D%E8%BD%AC%E9%93%BE%E8%A1%A8
详细分析可见力扣题解:
function reverse_list($head){
if($head == null) return null;
$pre = null;
$next = null;
while($head != null){
$next = $head->next;
$head->next = $pre;
$pre = $head;
$head = $next;
}
return $pre;
}