Skip to content

Commit 45bca55

Browse files
committed
Update Solution 019 [Python3]
1 parent 0ef0972 commit 45bca55

File tree

1 file changed

+25
-0
lines changed
  • solution/019.Remove Nth Node From End of List

1 file changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Definition for singly-linked list.
2+
# class ListNode:
3+
# def __init__(self, x):
4+
# self.val = x
5+
# self.next = None
6+
7+
class Solution:
8+
def removeNthFromEnd(self, head, n):
9+
"""
10+
:type head: ListNode
11+
:type n: int
12+
:rtype: ListNode
13+
"""
14+
pre=ListNode(-1)
15+
pre.next=head
16+
fast=pre
17+
slow=pre
18+
19+
for _ in range(n):
20+
fast=fast.next
21+
while fast.next:
22+
fast=fast.next
23+
slow=slow.next
24+
slow.next=slow.next.next
25+
return pre.next

0 commit comments

Comments
 (0)