zoukankan      html  css  js  c++  java
  • Leetcode练习(Python):哈希表类:第94题:给定一个二叉树,返回它的中序 遍历。

    题目:
    给定一个二叉树,返回它的中序 遍历。
    思路:
    练习过很多次了,都记住了,但是没有找到用哈希表的点。使用递归来实现很方便,掌握中序遍历的原理就好。
    程序:
    # Definition for a binary tree node.
    # class TreeNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.left = None
    #         self.right = None
    class Solution:
        def inorderTraversal(self, root: TreeNode) -> List[int]:
            result = []
            self.auxiliary(root, result)
            return result
        def auxiliary(self, root: TreeNode, result: List[int]):
            if root:
                self.auxiliary(root.left, result)
                result.append(root.val)
                self.auxiliary(root.right, result)
  • 相关阅读:
    Upgrading to MySQL 5.7---focusing on temporal types
    mysqldump备份7
    mysqldump原理5
    mysqldump原理4
    mysqldump原理3
    mysqldump原理2
    mysqldump原理1
    MySQL复制中slave延迟监控
    赵浮云的blog 关注IT运维,开源硬件。
    爱维帮---LVS
  • 原文地址:https://www.cnblogs.com/zhuozige/p/12793658.html
Copyright © 2011-2022 走看看