# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def middleNode(self, head: ListNode) -> ListNode: if head.next==None: return head r=[] while head: r.append(head.val) head=head.next r=r[len(r)//2:] head=ListNode(0) p=head for i in range(len(r)): p.next=ListNode(r[i]) p=p.next return head.next
执行用时 :40 ms, 在所有 python3 提交中击败了89.26%的用户
内存消耗 :13.7 MB, 在所有 python3 提交中击败了5.22%的用户
——2019.10.24
原文地址:https://www.cnblogs.com/taoyuxin/p/11731127.html
时间: 2024-11-09 10:43:33