"""Leetcode 590. N-ary Tree Postorder Traversal
Easy

URL: https://leetcode.com/problems/n-ary-tree-postorder-traversal/

Given an n-ary tree, return the postorder traversal of its nodes' values.

For example, given a 3-ary tree:
      1
    / | \
   3  2  4
  / \
 5   6
Return its postorder traversal as: [5,6,3,2,4,1].

Note:
Recursive solution is trivial, could you do it iteratively?
"""

# Definition for a Node.
class Node(object):
    def __init__(self, val, children):
        self.val = val
        self.children = children


class SolutionRecur(object):
    def _postorderRrecur(self, root, vals):
        if not root:
            return None

        # Collect children nodes's vals first.
        for child in root.children:
            self._postorderRrecur(child, vals)

        # Collect root node's val.
        vals.append(root.val)

    def postorder(self, root):
        """
        :type root: Node
        :rtype: List[int]

        Time complexity: O(n).
        Space complexity: O(n).
        """
        # Apply recursive postorder traversal.
        if not root:
            return []

        vals = []
        self._postorderRrecur(root, vals)
        return vals



def main():
    # For example, given a 3-ary tree:
    #       1
    #     / | \
    #    3  2  4
    #   / \
    #  5   6
    # Return its postorder traversal as: [5,6,3,2,4,1].
    root = Node(1, [])
    root.children.append(Node(3, []))
    root.children.append(Node(2, []))
    root.children.append(Node(4, []))
    root.children[0].children.append(Node(5, []))
    root.children[0].children.append(Node(6, []))
    print SolutionRecur().postorder(root)


if __name__ == '__main__':
    main()

@@ -1188,16 +1188,701 @@
  vals%0A%0A%0A
+class SolutionIter(object):%0A    def postorder(self, root):%0A        %22%22%22%0A        :type root: Node%0A        :rtype: List%5Bint%5D%0A%0A        Time complexity: O(n).%0A        Space complexity: O(n).%0A        %22%22%22%0A        # Apply iterative postorder traversal.%0A        if not root:%0A            return %5B%5D%0A%0A        # Collect reversed values by %22preorder%22 traversal with stack.%0A        rev_vals = %5B%5D%0A%0A        stack = %5Broot%5D %0A%0A        while stack:%0A            current = stack.pop()%0A%0A            rev_vals.append(current.val)%0A%0A            for child in current.children:%0A                # Iteratively append nodes to stack due to its FILO.%0A                stack.append(child)%0A%0A        return rev_vals%5B::-1%5D%0A%0A
 %0Adef mai
@@ -2286,24 +2286,25 @@
 ode(6, %5B%5D))%0A
+%0A
     print So
@@ -2333,16 +2333,57 @@
 r(root)%0A
+    print SolutionIter().postorder(root)%0A
 %0A%0Aif __n

Complete iter sol