leetcode Binary Tree Inorder Traversal 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]
"""
res=[]
stk=[]
if root == None:
return res
while root != None or len(stk) != 0:
if root != None:
stk.append(root)
root=root.left
elif len(stk) != 0:
tmpNode=stk.pop()
res.append(tmpNode.val)
root=tmpNode.right
return res
上一篇:c#: 模态窗口最小化主窗口


下一篇:CentOS7系统时间和硬件时间不同步问题