From d934276b3661f8e43456e1a42d2975230957940a Mon Sep 17 00:00:00 2001 From: Shlok Kumar <77238805+shlok2740@users.noreply.github.com> Date: Tue, 4 Oct 2022 15:22:42 +0530 Subject: [PATCH] Create Middle of the Linked List.py --- Easy problems/Middle of the Linked List.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Easy problems/Middle of the Linked List.py diff --git a/Easy problems/Middle of the Linked List.py b/Easy problems/Middle of the Linked List.py new file mode 100644 index 0000000..6cb5350 --- /dev/null +++ b/Easy problems/Middle of the Linked List.py @@ -0,0 +1,15 @@ +class ListNode: + def __init__(self, val=0, next=None): + self.val = val + self.next = next + +class Solution: + def middleNode(self, head: Optional[ListNode]) -> Optional[ListNode]: + slow=head + fast=head + + while fast and fast.next: + slow=slow.next + fast=fast.next.next + + return slow