Easy Understanding Java beat 95.7% with Explanation
Basic idea is straight forward: \n1. Start form the head , move one step each time to the next node\n2. When meet with a node with child, say node p, follow its
Basic idea is straight forward: \n1. Start form the `head` , move one step each time to the next node\n2. When meet with a node with child, say node `p`, follow its `child chain` to the end and connect the tail node with `p.next`, by doing this we merged the `child chain` back to the `main thread`\n3.  Return to `p` and proceed until find next node with child.\n4.  Repeat until reach `null`\n\n```\nclass Solution {\n    public Node flatten(Node head) {\n        if( head == null) return head;\n\t// Pointer\n        Node p = head; \n        while( p!= null) {\n            /* CASE 1: if no child, proceed */\n            if( p.child == null ) {\n                p = p.next;\n                continue;\n            }\n            /* CASE 2: got child, find the tail of the child and link it to p.next */\n            Node temp = p.child;\n            // Find the tail of the child\n            while( temp.next != null ) \n                temp = temp.next;\n            // Connect tail with p.next, if it is not null\n            temp.next = p.next;  \n            if( p.next != null )  p.next.prev = temp;\n            // Connect p with p.child, and remove p.child\n            p.next = p.child; \n            p.child.prev = p;\n            p.child = null;\n        }\n        return head;\n    }\n}\n```
[]