Skip to content

Commit b6a661b

Browse files
committed
added lc_19_sol
1 parent 843afba commit b6a661b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

19.remove-nth-from-end-of-list.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
3+
class ListNode:
4+
def __init__(self, val=0, next=None):
5+
self.val = val
6+
self.next = next
7+
8+
9+
10+
11+
def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode:
12+
dummy = ListNode(0, head)
13+
current = dummy
14+
second = head
15+
16+
while n > 0 and second:
17+
second = second.next
18+
n-=1
19+
20+
while second:
21+
second = second.next
22+
current = current.next
23+
current.next = current.next.next
24+
25+
return dummy.next

0 commit comments

Comments
 (0)