Given a non-empty, singly?linked list with head node?head, return?a?middle node of linked list.
If there are two middle nodes, return the second middle node.
class Solution:
? ? def middleNode(self, head):
? ? ? ? """
? ? ? ? :type head: ListNode
? ? ? ? :rtype: ListNode
? ? ? ? """
? ? ? ? slow = fast = head
? ? ? ? while fast and fast.next:
? ? ? ? ? ? slow = slow.next
? ? ? ? ? ? fast = fast.next.next
? ? ? ? return slow
1 返回的是list
2 重點(diǎn)在fast和slow的指針割岛,當(dāng)fast跑完,slow整好是我們想要的