Skip to content

Commit 55fcb2f

Browse files
committed
Leetcode 237
1 parent f7fe611 commit 55fcb2f

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

201-250/237.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
## :pencil2:Leetcode之PHP版题目解析(237. Delete Node in a Linked List)
2+
**2020-04-10 吴亲库里 库里的深夜食堂**
3+
****
4+
### :pencil2:描述
5+
**写一个方法,删除链表中的节点,仅仅对该节点有访问权限.什么意思?也就是说,在这个节点之前的节点信息你是看不到的,而且此链表是个单项链表 题目也说明了节点不会是列表的末尾节点**
6+
****
7+
### :pencil2:题目实例
8+
<a href="https://github.com/wuqinqiang/">
9+
​ <img src="https://github.com/wuqinqiang/Lettcode-php/blob/master/images/237.png">
10+
</a>
11+
****
12+
13+
### :pencil2:题目分析
14+
15+
**和往常不太一样,之前删除链表中的节点的时候都会传入头结点,和一个要删除的节点值.然后我们需要把待删除节点的上一个节点的next指针指向待删除的节点的next节点,由于我们现在并不知道待删除节点的上一个节点,因此这种做法就失效了.其实解题思路就是把当前这个要删除的节点的值改成下一个节点的值,然后把当前结点的next指针指向下下一个结点就行了.可以思考一下**
16+
17+
```php
18+
/**
19+
* Definition for a singly-linked list.
20+
* class ListNode {
21+
* public $val = 0;
22+
* public $next = null;
23+
* function __construct($val) { $this->val = $val; }
24+
* }
25+
*/
26+
27+
class Solution {
28+
/**
29+
* @param ListNode $node
30+
* @return
31+
*/
32+
function deleteNode($node) {
33+
$node->val=$node->next->val;
34+
$node->next=$node->next->next;
35+
}
36+
}
37+
```
38+
****
39+
40+
### 联系
41+
42+
<a href="https://github.com/wuqinqiang/">
43+
​ <img src="https://github.com/wuqinqiang/Lettcode-php/blob/master/qrcode_for_gh_c194f9d4cdb1_430.jpg" width="150px" height="150px">
44+
</a>
45+
46+
47+
48+
49+

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@
188188
- [Leetcode230](https://github.com/wuqinqiang/Lettcode-php/blob/master/201-250/230.md)
189189
- [Leetcode231](https://github.com/wuqinqiang/Lettcode-php/blob/master/201-250/231.md)
190190
- [Leetcode232](https://github.com/wuqinqiang/Lettcode-php/blob/master/201-250/232.md)
191+
- [Leetcode237](https://github.com/wuqinqiang/Lettcode-php/blob/master/201-250/237.md)
191192
- [Leetcode238](https://github.com/wuqinqiang/Lettcode-php/blob/master/201-250/238.md)
192193
- [Leetcode234](https://github.com/wuqinqiang/Lettcode-php/blob/master/201-250/234.md)
193194
- [Leetcode240](https://github.com/wuqinqiang/Lettcode-php/blob/master/201-250/240.md)

images/237.png

185 KB
Loading

0 commit comments

Comments
 (0)