郑州市建设网站,上海市企业服务云登录,镇江网页制作,wordpress博客导航Problem: 94. 二叉树的中序遍历 文章目录 思路 解题方法复杂度Code 思路 解题方法 二叉树简单递归。 复杂度
时间复杂度: O ( n ) O(n) O(n) 空间复杂度: O ( n ) O(n) O(n) Code
# Definition for a binary tree node.
# class TreeNode:
# def __init__(se… Problem: 94. 二叉树的中序遍历 文章目录 思路 解题方法复杂度Code 思路 解题方法 二叉树简单递归。 复杂度
时间复杂度: O ( n ) O(n) O(n) 空间复杂度: O ( n ) O(n) O(n) Code
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val0, leftNone, rightNone):
# self.val val
# self.left left
# self.right right
class Solution:def inorderTraversal(self, root: Optional[TreeNode]) - List[int]:if not root:return []return self.inorderTraversal(root.left) [root.val] self.inorderTraversal(root.right)