Java recursive, beat 100%, similar to flatten tree
Think of structure as being a binary tree structure. Then you can solve it similarly to the flatten tree problem: https://leetcode.com/problems/flatten-binary-t
Think of structure as being a binary tree structure. Then you can solve it similarly to the flatten tree problem: https://leetcode.com/problems/flatten-binary-tree-to-linked-list/\n\n\n```\nclass Solution {\n    \n    Node prev = null;\n    \n    public Node flatten(Node head) {\n        dfsHelper(head);\n        return head;\n    }\n    \n    public void dfsHelper(Node current) {\n        if (current == null) return;\n        // postorder traversal, going right first or next in this case\n        dfsHelper(current.next);\n        dfsHelper(current.child);\n\t\t// don\'t forget to set prev.prev pointer \n        if (prev != null) prev.prev = current;\n\t\t// see explanation below\n        current.next = prev;\n        current.child = null;\n        prev = current;\n    }\n}\n```\n\nWhat\'s happening with pointer assignments\n\n```\n     *    1\n     *    / \\\n     *   2   5\n     *  / \\   \\\n     * 3   4   6\n     * -----------\n     * pre = 5\n     * cur = 4\n     *\n     *     1\n     *    /\n     *   2\n     *  / \\\n     * 3   4\n     *      \\\n     *       5\n     *        \\\n     *         6\n     * -----------\n     * pre = 4\n     * cur = 3\n     *\n     *     1\n     *    /\n     *   2\n     *  /\n     * 3\n     *  \\\n     *   4\n     *    \\\n     *     5\n     *      \\\n     *       6\n     * -----------\n     * cur = 2\n     * pre = 3\n     *\n     *     1\n     *    /\n     *   2\n     *    \\\n     *     3\n     *      \\\n     *       4\n     *        \\\n     *         5\n     *          \\\n     *           6\n     * -----------\n     * cur = 1\n     * pre = 2\n     *\n     * 1\n     *  \\\n     *   2\n     *    \\\n     *     3\n     *      \\\n     *       4\n     *        \\\n     *         5\n     *          \\\n     *           6\n```
['Depth-First Search', 'Recursion', 'Java']