• 栈和队列_leetcode94


    class Solution(object):
    def inorderTraversal(self, root):
    """
    :type root: TreeNode
    :rtype
    """

    res = []
    self.order(root, res)
    return res


    def order(self, root, res):
    if root:

    self.order(root.left, res)
    res.append(root.val)
    self.order(root.right, res)


    class Solution2(object):
    def inorderTraversal(self, root):
    """
    :type root: TreeNode
    :rtype
    """

    class Command(object):
    def __init__(self, com, node):
    self.com = com
    self.node = node

    res = []
    stack = []

    if not root:
    return res
    stack.append(Command("go", root))

    while stack:
    com = stack.pop()

    if com.com == "print":
    res.append(com.node.val)
    else:
    if com.node.right:
    stack.append(Command("go", com.node.right))
    stack.append(Command("print", com.node))
    if com.node.left:
    stack.append(Command("go", com.node.left))

    return res
  • 相关阅读:
    增删改
    创建数据库
    数据库的列类型
    数据库
    Python os.ttyname() 方法
    Python os.tmpnam() 方法
    Python os.tmpfile() 方法
    Python os.tempnam() 方法
    Python os.tcsetpgrp() 方法
    LR运行负载测试场景-笔记
  • 原文地址:https://www.cnblogs.com/lux-ace/p/10547319.html
Copyright © 2020-2023  润新知