LC.P430[扁平化多级双向链表] 方法一:迭代1234567891011121314151617181920212223242526272829/*// Definition for a Node.class Node { public int val; public Node prev; public Node next; public Node child;};*/class Solution { public Node flatten(Node head) { Node dummy = new Node(); for (dummy.next = head; head != null; head = head.next) { if (head.child != null) { Node temp = head.next; Node child = head.child; head.next = child; child.prev = head; head.child = null; Node cur = head; while (cur.next != null) cur = cur.next; cur.next = temp; if (temp != null) temp.prev = cur; } } return dummy.next; }} 时间复杂度:$O(n)$ 空间复杂度:$O(1)$