Subject:
python3 code:
# 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: TreeNode) -> List[int]:
if not root:
return list() # 或者 return []
res = []
self.postTraversal(root, res)
return res
def postTraversal(self, root, res):
if root:
self.postTraversal(root.left, res)
self.postTraversal(root.right, res)
res.append(root.val)
If you think it's good, please
like and follow the message~ Thank you~