# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def middleNode(self, head: Optional[ListNode]) -> Optional[ListNode]:
slow=head
fast=head.next
while fast and fast.next:
slow=slow.next
fast=fast.next.next
if fast:
return slow.next
return slow
LEETCODE 876. 链表的中间结点
最新推荐文章于 2024-08-09 20:06:48 发布