方法1
class Solution:
def inorderTraversal(self, root: TreeNode) -> List[int]:
res = []
def help(root: TreeNode):
if(root is None):
return None
help(root.left)
res.append(root.val)
help(root.right)
help(root)
return res
方法2
class Solution:
def inorderTraversal(self, root: TreeNode) -> List[int]:
global res
res = []
self.help(root)
return res
def help(self,root):
if(root is None):
return None
self.help(root.left)
res.append(root.val)
self.help(root.right)
猜你喜欢:👇🏻
⭐【Python】函数外定义变量并在函数内进行更新
⭐【Python】函数默认参数怎么改变?
⭐【Python】生成器有啥用?