leetcode 143. Reorder List 发表于 2019-01-02 | 分类于 leetcode 题目链接:leetcode 思路:链表 123456789101112131415161718192021222324252627282930# Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# self.val = x# self.next = Noneclass Solution(object): def reorderList(self, head): """ :type head: ListNode :rtype: void Do not return anything, modify head in-place instead. """ if not head:return None slow = node = head fast = slow.next stack=[] while fast and fast.next: slow = slow.next fast = fast.next.next new_slow = slow.next slow.next = None while new_slow: stack.append(new_slow) new_slow = new_slow.next while node: next_node = node.next if stack: node.next=stack.pop() node.next.next = next_node node = next_node