二叉树的中序遍历
程序员文章站
2022-03-14 23:02:10
...
Python
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def inorderTraversal(self, root):
"""
:type root: TreeNode
:rtype: List[int]
"""
l = []
self.visitNode(root, l)
return l
def visitNode(self, root, l):
if root is None:
return
self.visitNode(root.left, l)
l.append(root.val)
self.visitNode(root.right, l)
上一篇: 最近学习了一上PHP的东东
下一篇: PHP中文网带你看php文件操作