kucheasysa

Algoverse_adesh_39

Jul 8th, 2024
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. # Definition for singly-linked list.
  2. # class ListNode:
  3. #     def __init__(self, val=0, next=None):
  4. #         self.val = val
  5. #         self.next = next
  6. class Solution:
  7.     def deleteMiddle(self, head: Optional[ListNode]) -> Optional[ListNode]:
  8.         if not head or not head.next:
  9.             return None
  10.         fast = head
  11.         slow = ListNode()
  12.        
  13.         slow.next = head
  14.         while fast and fast.next:
  15.             fast = fast.next.next
  16.             slow = slow.next
  17.         slow.next = slow.next.next
  18.         return head
Advertisement
Add Comment
Please, Sign In to add comment