bumpsoo 2026-06-15 13:05:01 +00:00
parent 1fe0c770f9
commit 5ee734e9a5

View file

@ -0,0 +1,20 @@
# https://leetcode.com/problems/delete-the-middle-node-of-a-linked-list
from typing import Optional
class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
class Solution:
def deleteMiddle(self, head: Optional[ListNode]) -> Optional[ListNode]:
if head is None or head.next is None:
return None
slow = head
fast = head.next.next
while fast is not None and fast.next is not None:
slow = slow.next
fast = fast.next.next
slow.next = slow.next.next
return head