Post-order Traversal

In this, the parent is considered after both the left child and right child. Let's say, a tree with node 3 has children node 1 and node 2. Then, in this traversal, we will print node 1 first, then node 3 and node 2 follows.

E.g. [1, 2, 3]

class Traversal:    
    def postOrderTraversal(self, root):
        def fun(root, result):
            if not root:
                return

            fun(root.left, result)
            fun(root.right, result)
            result.append(root.val)
        
        result = []
        fun(root, result)

        return result

Now, go ahead and solve this problem: https://leetcode.com/problems/binary-tree-postorder-traversal

Discussion

2

0