# 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 inorderTraversal(self, root: Optional[TreeNode]) -> List[int]:
def dfs(cur):
if not cur:
return
# # 中序递归
dfs(cur.left)
res.append(cur.val)
dfs(cur.right)
res = []
dfs(root)
return res
我不理解,这里的res作为inoderTarversal的变量,是处于dfs函数体外的,那么dfs为什么可以对res进行append操作?