Movatterモバイル変換


[0]ホーム

URL:


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

Commit1a65306

Browse files
committed
19-remove-nth-node-from-end-of-list.md Separated Chinese and English solutions.
1 parent3dedbca commit1a65306

File tree

2 files changed

+31
-91
lines changed

2 files changed

+31
-91
lines changed

‎en/1-1000/19-remove-nth-node-from-end-of-list.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ return dummy_head.next
7979
```
8080

8181
##Complexity
82-
* Time:`O(n)`.
82+
* Time:`O(N)`.
8383
* Space:`O(1)`.
8484

8585
##Java

‎zh/1-1000/19-remove-nth-node-from-end-of-list.md

Lines changed: 30 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,46 @@
1-
#19. Remove Nth Node From End of List - Best Practices of LeetCode Solutions
2-
LeetCode link:[19. Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list),
3-
[19. 删除链表的倒数第 N 个结点](https://leetcode.cn/problems/remove-nth-node-from-end-of-list)
1+
#19. 删除链表的倒数第 N 个结点 - 力扣题解最佳实践
2+
力扣链接:[19. 删除链表的倒数第 N 个结点](https://leetcode.cn/problems/remove-nth-node-from-end-of-list), 难度:**中等**
43

5-
[中文题解](#中文题解)
6-
7-
##LeetCode problem description
8-
Given the`head` of a linked list, remove the`n-th` node from the end of the list and return_its head_.
4+
##力扣“19. 删除链表的倒数第 N 个结点”问题描述
5+
给你一个链表,删除链表的倒数第`n` 个结点,并且返回链表的头结点。
96

10-
###[Example 1]
7+
###[示例 1]
118
![](../../images/examples/19_1.jpg)
129

13-
**Input**:`head = [1,2,3,4,5], n = 2`
10+
**输入**:`head = [1,2,3,4,5], n = 2`
1411

15-
**Output**:`[1,2,3,5]`
12+
**输出**:`[1,2,3,5]`
1613

17-
###[Example 2]
18-
**Input**:`head = [1], n = 1`
14+
###[示例 2]
15+
**输入**:`head = [1], n = 1`
1916

20-
**Output**:`[]`
17+
**输出**:`[]`
2118

22-
###[Example 3]
23-
**Input**:`head = [1,2], n = 1`
19+
###[示例 3]
20+
**输入**:`head = [1,2], n = 1`
2421

25-
**Output**:`[1]`
22+
**输出**:`[1]`
2623

27-
###[Constraints]
28-
-The number of nodes in the list is`sz`.
24+
###[约束]
25+
-链表中结点的数目为`sz`
2926
-`1 <= sz <= 30`
3027
-`0 <= Node.val <= 100`
3128
-`1 <= n <= sz`
3229

30+
###[提示]
3331
<details>
34-
<summary>Hint 1</summary>
35-
Maintain two pointers and update one with a delay of n steps.
32+
<summary>提示 1</summary>
33+
Maintain two pointers and update one with a delay of n steps.
3634
</details>
3735

38-
##Intuition
39-
[中文题解](#中文题解)
40-
41-
1. Deleting the`N-th` to last node in a linked list is equivalent to deleting the`node_count - N`-th node in the linked list.
42-
2. First find out`node_count`.
43-
3. When`index == node_count - N`, delete the node by`node.next = node.next.next`.
44-
4. Since the deleted node may be`head`, a virtual node`dummy_node` is used to facilitate unified processing.
36+
##思路
37+
1. 删除链表的倒数第`N` 个结点,等同于删除链表的第`node_count - N` 个结点。
38+
2. 先求出`node_count`
39+
3.`index == node_count - N`时,进行删除节点操作:`node.next = node.next.next`
40+
4. 由于删除的节点可能是`head`,所以使用虚拟节点`dummy_node`,方便统一处理。
4541

46-
##Steps to the Solution
47-
1.First find out`node_count`.
42+
##步骤
43+
1.求出`node_count`
4844
```ruby
4945
node_count=0
5046
node= head
@@ -55,7 +51,7 @@ while node
5551
end
5652
```
5753

58-
2.When`index == node_count - N`, delete the node by`node.next = node.next.next`.
54+
2.`index == node_count - N`时,进行删除节点操作:`node.next = node.next.next`
5955
```ruby
6056
index=0
6157
node= head
@@ -71,7 +67,7 @@ while node
7167
end
7268
```
7369

74-
3.Since the deleted node may be`head`, a virtual node`dummy_node` is used to facilitate unified processing.
70+
3.由于删除的节点可能是`head`,所以使用虚拟节点`dummy_node`,方便统一处理。
7571
```ruby
7672
dummy_head=ListNode.new# 1
7773
dummy_head.next= head# 2
@@ -82,9 +78,9 @@ node = dummy_head # 3
8278
return dummy_head.next
8379
```
8480

85-
##Complexity
86-
*Time:`O(n)`.
87-
*Space:`O(1)`.
81+
##复杂度
82+
*时间:`O(N)`
83+
*空间:`O(1)`
8884

8985
##Java
9086
```java
@@ -380,59 +376,3 @@ end
380376
```
381377
// Welcome to create a PR to complete the code of this language, thanks!
382378
```
383-
384-
##问题描述
385-
给你一个链表,删除链表的倒数第`n` 个结点,并且返回链表的头结点。
386-
387-
###[Example 1]
388-
![](../../images/examples/19_1.jpg)
389-
390-
**输入**:`head = [1,2,3,4,5], n = 2`
391-
392-
**输出**:`[1,2,3,5]`
393-
394-
#中文题解
395-
##思路
396-
1. 删除链表的倒数第`N` 个结点,等同于删除链表的第`node_count - N` 个结点。
397-
2. 先求出`node_count`
398-
3.`index == node_count - N`时,进行删除节点操作:`node.next = node.next.next`
399-
4. 由于删除的节点可能是`head`,所以使用虚拟节点`dummy_node`,方便统一处理。
400-
401-
##步骤
402-
1. 求出`node_count`
403-
```ruby
404-
node_count=0
405-
node= head
406-
407-
while node
408-
node_count+=1
409-
node= node.next
410-
end
411-
```
412-
413-
2.`index == node_count - N`时,进行删除节点操作:`node.next = node.next.next`
414-
```ruby
415-
index=0
416-
node= head
417-
418-
while node
419-
if index== node_count- n
420-
node.next= node.next.next
421-
break
422-
end
423-
424-
index+=1
425-
node= node.next
426-
end
427-
```
428-
429-
3. 由于删除的节点可能是`head`,所以使用虚拟节点`dummy_node`,方便统一处理。
430-
```ruby
431-
dummy_head=ListNode.new# 1
432-
dummy_head.next= head# 2
433-
node= dummy_head# 3
434-
435-
# omitted code
436-
437-
return dummy_head.next
438-
```

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp