Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ed6f8ce

Browse files
committed
Feat: leetcode206
1 parent fa7774e commit ed6f8ce

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

‎problems/206-everse-linked-list.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
## 题目
2+
3+
* 206. 反转链表
4+
5+
给你单链表的头节点 head ,请你反转链表,并返回反转后的链表。
6+
7+
## 思路
8+
9+
## 代码
10+
11+
```php
12+
/**
13+
* Definition for a singly-linked list.
14+
* class ListNode {
15+
* public $val = 0;
16+
* public $next = null;
17+
* function __construct($val = 0, $next = null) {
18+
* $this->val = $val;
19+
* $this->next = $next;
20+
* }
21+
* }
22+
*/
23+
class Solution {
24+
25+
/**
26+
* @param ListNode $head
27+
* @return ListNode
28+
*/
29+
function reverseList($head) {
30+
$pre = null;
31+
$cur = $head;
32+
while($cur){
33+
$next = $cur->next;
34+
$cur->next = $pre;
35+
$pre = $cur;
36+
$cur = $next;
37+
}
38+
return $pre;
39+
}
40+
}
41+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /