leetcode——876. 链表的中间结点

# 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
posted @ 2019-10-24 11:19  欣姐姐  阅读(97)  评论(0编辑  收藏  举报