package leetcode;

/**
 * https://leetcode.com/problems/flatten-a-multilevel-doubly-linked-list/
 */
public class Problem430 {
    private static class Node {
        public int val;
        public Node prev;
        public Node next;
        public Node child;

        public Node() {
        }

        public Node(int _val, Node _prev, Node _next, Node _child) {
            val = _val;
            prev = _prev;
            next = _next;
            child = _child;
        }
    }

    public Node flatten(Node head) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem430 prob = new Problem430();
    }
}

@@ -530,35 +530,546 @@
     
-// TODO%0A        return null
+for (Node n = head; n != null; n = n.next) %7B%0A            if (n.child != null) %7B%0A                Node tmp = n.next;%0A                n.next = n.child;%0A                Node cn = n.child;%0A                while (cn.next != null) %7B%0A                    cn = cn.next;%0A                %7D%0A                cn.next = tmp;%0A            %7D%0A        %7D%0A        return head;%0A    %7D%0A%0A    private static void print(Node head) %7B%0A        for (Node n = head; n != null; n = n.next) %7B%0A            System.out.print(n.val + ' ');%0A        %7D%0A        System.out.println()
 ;%0A  

Update problem 430