144. 二叉树的前序遍历:
代码思路
class Solution:
def postorderTraversal(self, root: TreeNode) -> List[int]:
def postorder(root: TreeNode):
if not root:
return
res.append(root.val)
postorder(root.left)
postorder(root.right)
res = list()
postorder(root)
return res
144. 二叉树的中序遍历:
代码思路
class Solution:
def postorderTraversal(self, root: TreeNode) -> List[int]:
def postorder(root: TreeNode):
if not root:
return
postorder(root.left)
res.append(root.val)
postorder(root.right)
res = list()
postorder(root)
return res
144. 二叉树的后序遍历:
代码思路
class Solution:
def postorderTraversal(self, root: TreeNode) -> List[int]:
def postorder(root: TreeNode):
if not root:
return
postorder(root.left)
postorder(root.right)
res.append(root.val)
res = list()
postorder(root)
return res