Simple Python Solution Using Stack


#1
# Definition for a  binary tree node
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution:
    # @param A : root node of tree
    # @return a list of integers
    def inorderTraversal(self, A):
        seen={}
        out_li=[]
        stack=[A]
        while(stack!=[]):
            if stack[-1].left and stack[-1].left.val not in seen:
                stack.append(stack[-1].left)
            
            else:
                temp=stack.pop()
                out_li.append(temp.val)
                if temp.right:
                    stack.append(temp.right)
                seen[temp.val]=1
        return out_li