mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
@ -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是当前节点
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
-----------------------
|
||||
|
Reference in New Issue
Block a user