diff --git a/problems/0206.翻转链表.md b/problems/0206.翻转链表.md index 25b16907..a2ae2ce1 100644 --- a/problems/0206.翻转链表.md +++ b/problems/0206.翻转链表.md @@ -496,8 +496,26 @@ struct ListNode* reverseList(struct ListNode* head){ return reverse(NULL, head); } ``` -Scala: + + +PHP: +```php +// 双指针法: +function reverseList($head) { + $cur = $head; + $pre = NULL; + while($cur){ + $temp = $cur->next; + $cur->next = $pre; + $pre = $cur; + $cur = $temp; + } + return $pre; + } +``` + +Scala: 双指针法: ```scala object Solution { @@ -529,6 +547,7 @@ object Solution { cur.next = pre reverse(cur, tmp) // 此时cur成为前一个节点,tmp是当前节点 } + } ``` -----------------------