Created
May 19, 2022 05:11
-
-
Save thekhairul/a918612df1a3e5538906d4044a1d66b9 to your computer and use it in GitHub Desktop.
Leetcode 2095: Delete the Middle Node of a Linked List - python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def deleteMiddle(head): | |
if head.next: | |
slow = head | |
fast = head | |
beforeMid = None | |
while fast and fast.next: | |
fast = fast.next.next | |
beforeMid = slow | |
slow = slow.next | |
beforeMid.next = slow.next | |
return head | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment