class Solution:
# @param root, a tree node
# @return a list of integers
def inorderTraversal(self, root):
if root == None:
return []
result = []
visited = []
stack = [root]
while stack != []:
node = stack.pop()
if node in visited:
result.append(node.val)
continue
visited.append(node)
if node.right != None:
stack.append(node.right)
stack.append(node)
if node.left != None:
stack.append(node.left)
return result
My accepted code in Python


Thanks for your post. However it would be better to share solution with correct code format and elaborated thoughts. Please read the Discuss FAQ for more info. Take a look at good sharing example