Skip to content

Commit 5704bca

Browse files
committed
committed from zkp
1 parent 1fead87 commit 5704bca

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

LeetCode/removeNthFromEnd_1.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Definition for singly-linked list.
2+
# class ListNode(object):
3+
# def __init__(self, x):
4+
# self.val = x
5+
# self.next = None
6+
7+
class Solution(object):
8+
def removeNthFromEnd(self, head, n):
9+
"""
10+
:type head: ListNode
11+
:type n: int
12+
:rtype: ListNode
13+
"""
14+
dummy = ListNode(0)
15+
dummy.next = head
16+
first = dummy
17+
for i in range(n + 1):
18+
first = first.next
19+
second = dummy
20+
while first is not None:
21+
first = first.next
22+
second = second.next
23+
second.next = second.next.next
24+
return dummy.next

0 commit comments

Comments
 (0)