145. 二叉树的后序遍历
问题描述
https://leetcode.cn/problems/binary-tree-postorder-traversal/description/
解题思路
这个题和先序一样,没啥好说的。
代码
# Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right class Solution: def postorderTraversal(self, root: Optional[TreeNode]) -> List[int]: res = [] def dfs(root): if root is None: return dfs(root.left) dfs(root.right) res.append(root.val) dfs(root) return res