lc876. 链表的中间结点

# 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: ListNode) -> ListNode:
       slow = head       
       fast = head
       while fast.next != None:
           if fast.next.next == None:
               slow = slow.next
               break
           slow = slow.next
           fast = fast.next.next   
       return slow

 

posted @ 2022-05-05 16:19  stronger_el  阅读(58)  评论(0)    收藏  举报