From 23a7e51d9cd7d1619f4c0a09f589793f62eacfac Mon Sep 17 00:00:00 2001 From: shatakshi1234 <116963781+shatakshi1234@users.noreply.github.com> Date: Mon, 31 Oct 2022 22:34:21 +0530 Subject: [PATCH] Create Remove Nth Node From End of List --- Remove Nth Node From End of List | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Remove Nth Node From End of List 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