# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def reorderList(self, head: ListNode) -> None:
"""
Do not return anything, modify head in-place instead.
"""
alist = []
pre = head
while pre:
alist.append(pre)
pre = pre.next
left,right = 0,len(alist)-1
while left < right:
alist[left].next = alist[right]
left += 1
if left >= right:
break
alist[right].next = alist[left]
right -= 1
alist[left].next = None
return head
leetcode143重排链表
最新推荐文章于 2025-05-10 16:26:05 发布