diff --git a/Remove Nth Node From End of List b/Remove Nth Node From End of List new file mode 100644 index 0000000..3166b62 --- /dev/null +++ b/Remove Nth Node From End of List @@ -0,0 +1,8 @@ +class Solution: + def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode: + fast, slow = head, head + for _ in range(n): fast = fast.next + if not fast: return head.next + while fast.next: fast, slow = fast.next, slow.next + slow.next = slow.next.next + return head