# 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]:
fast = head
slow = head
while fast:
if not fast.next:
return slow
if fast.next and (not fast.next.next):
return slow.next
fast = fast.next.next
slow = slow.next
leetcode 876 链表的中间节点
最新推荐文章于 2024-07-25 11:15:54 发布