We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5e18608 commit 013ba05Copy full SHA for 013ba05
problems/0019.删除链表的倒数第N个节点.md
@@ -112,6 +112,30 @@ class Solution {
112
}
113
114
```
115
+
116
+Python:
117
+```python
118
+# Definition for singly-linked list.
119
+# class ListNode:
120
+# def __init__(self, val=0, next=None):
121
+# self.val = val
122
+# self.next = next
123
+class Solution:
124
+ def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode:
125
+ head_dummy = ListNode()
126
+ head_dummy.next = head
127
128
+ slow, fast = head_dummy, head_dummy
129
+ while(n!=0): #fast先往前走n步
130
+ fast = fast.next
131
+ n -= 1
132
+ while(fast.next!=None):
133
+ slow = slow.next
134
135
+ #fast 走到结尾后,slow的下一个节点为倒数第N个节点
136
+ slow.next = slow.next.next #删除
137
+ return head_dummy.next
138
+```
139
Go:
140
```Go
141
/**
0 commit comments