commit
e8d1a1a36b
|
|
@ -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是当前节点
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue