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