Java pre-order and post-order solution same idea with 114. Flatten Binary Tree to Linked List
The idea is same as 114. Just imagine the attrs "child" and "next" in the Node as "left" and "right" in the TreeNode. You will find actually, this multi-level l
The idea is same as 114. Just imagine the attrs "child" and "next" in the Node as "left" and "right" in the TreeNode. You will find actually, this multi-level linkedList is a tree but just add parent node as "prev". (Note: I met this problem when I was onsite interview with Bloomberg last year, that time I cannot solve it, wish I have done it before interview. lol )\nPre-Order\n```\n    Node pre = null;\n    public Node flatten(Node head) {\n        if (head == null) return head;\n        Node child = head.child;\n        Node next = head.next;\n        if (pre == null) {\n            pre = head;\n        } else {\n            pre.next = head;\n            head.prev = pre;\n            pre.child = null;\n        }\n        pre = head;\n        flatten(child);\n        flatten(next);\n        return head;\n    }\n```\nPost-Order\n```\n\tNode pre = null;\n    public Node flatten(Node head) {\n        if (head == null) return head;\n       \n        flatten(head.next);\n        flatten(head.child);\n        \n        head.next = pre;\n        \n        if (pre != null) {\n             pre.prev = head;\n        }\n\n        head.child = null;\n        pre = head;\n        return head;\n        \n    }\n
[]