145. Binary Tree Postorder Traversal - LeetCode Solution


Stack Tree Binary tree

Python Code:

class Solution:
    def postorderTraversal(self, root: Optional[TreeNode]) -> List[int]:
        ans = []
        
        def trav(root):
            if not root:
                return 
            
            trav(root.left)
            trav(root.right)
        
            ans.append(root.val)
        
        trav(root)
        return ans


Comments

Submit
0 Comments
More Questions

12C - Fruits
447B - DZY Loves Strings
325A - Square and Rectangles
1674F - Desktop Rearrangement
1140A - Detective Book
899A - Splitting in Teams
343A - Rational Resistance
1437D - Minimal Height Tree
1100C - NN and the Optical Illusion
1102E - Monotonic Renumeration
1682B - AND Sorting
1178C - Tiles
733C - Epidemic in Monstropolis
15C - Industrial Nim
40A - Find Color
1696E - Placing Jinas
700A - As Fast As Possible
1331C - And after happily lived ever they
1468J - Road Reform
1361B - Johnny and Grandmaster
1151A - Maxim and Biology
1472E - Correct Placement
1388B - Captain Flint and a Long Voyage
898C - Phone Numbers
558A - Lala Land and Apple Trees
534C - Polycarpus' Dice
368A - Sereja and Coat Rack
1279C - Stack of Presents
1380C - Create The Teams
1228B - Filling the Grid