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

 

posted @ 2015-12-06 22:25  hao.ma  阅读(132)  评论(0编辑  收藏  举报