2095. Delete the Middle Node of a Linked List
https://leetcode.com/problems/delete-the-middle-node-of-a-linked-list/submissions/
Python
class Solution:
def deleteMiddle(self, head: Optional[ListNode]) -> Optional[ListNode]:
dummy = ListNode(next=head)
length = 1
slow, fast = dummy, head
while fast.next:
length += 1
fast = fast.next
if length % 2 == 0:
slow = slow.next
slow.next = slow.next.next
return dummy.next