leetcode 94. Binary Tree Inorder Traversal 发表于 2018-09-21 | 分类于 leetcode 题目链接:leetcode链接 思路:中序遍历迭代型,非递归 1234567891011121314151617181920212223242526# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution(object): def inorderTraversal(self, root): """ :type root: TreeNode :rtype: List[int] """ stack = [] res = [] while True: if root: stack.append(root) root = root.left else: if len(stack) == 0: break root = stack.pop() res.append(root.val) root = root.right return res