diff --git a/DeleteTheMiddleNode(linkedlist).py b/DeleteTheMiddleNode(linkedlist).py new file mode 100644 index 0000000..6cea6ec --- /dev/null +++ b/DeleteTheMiddleNode(linkedlist).py @@ -0,0 +1,18 @@ +''' +Delete the middle node of linked list (2095) +''' + +class Solution: + def deleteMiddle( self, head : Optional[ListNode]): + if head == None or head.next == None: + return None + + slow = head + fast = head.next.next + + while fast and fast.next != None: + slow = slow.next + fast = fast.next.next + + slow.next = slow.next.next + return head