Merge pull request #1398 from fmtvar/0206

添加 (0206.翻转链表.md):PHP版本
This commit is contained in:
程序员Carl
2022-06-26 11:12:56 +08:00
committed by GitHub

View File

@ -496,8 +496,26 @@ struct ListNode* reverseList(struct ListNode* head){
return reverse(NULL, 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 ```scala
object Solution { object Solution {
@ -529,6 +547,7 @@ object Solution {
cur.next = pre cur.next = pre
reverse(cur, tmp) // 此时cur成为前一个节点tmp是当前节点 reverse(cur, tmp) // 此时cur成为前一个节点tmp是当前节点
} }
} }
``` ```
----------------------- -----------------------