leetcode 430. Flatten a Multilevel Doubly Linked List 发表于 2019-01-09 | 分类于 leetcode 题目链接:leetcode 思路:链表 1234567891011121314151617181920212223242526"""# Definition for a Node.class Node: def __init__(self, val, prev, next, child): self.val = val self.prev = prev self.next = next self.child = child"""class Solution: def flatten(self, head): """ :type head: Node :rtype: Node """ stack,cur = [],head while cur: if cur.child: if cur.next: stack.append(cur.next) cur.next,cur.child.prev,cur.child = cur.child,cur,None if not cur.next and len(stack) >0: tmp = stack.pop() tmp.prev,cur.next = cur,tmp cur = cur.next return head