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 d596ca5 commit f432bc8Copy full SHA for f432bc8
leetcode_Python/remove_nth_node.py
@@ -0,0 +1,21 @@
1
+# Definition for singly-linked list.
2
+# class ListNode:
3
+# def __init__(self, val=0, next=None):
4
+# self.val = val
5
+# self.next = next
6
+class Solution:
7
+ def removeNthFromEnd(self, head, n: int):
8
+ fast = slow = head
9
+ for _ in range(n):
10
+ fast = fast.next
11
+
12
+ if not fast:
13
+ return head.next
14
15
+ while fast.next:
16
17
+ slow = slow.next
18
+ slow.next = slow.next.next
19
+ return head
20
21
+# LINK : https://leetcode.com/problems/remove-nth-node-from-end-of-list/
0 commit comments