blog root self 思路 mar pre 元素 使用 binary
- # 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]
- """
- ret = []
- stack = []
- while root or stack:
- while root:
- stack.append(root)
- root = root.left
- if stack:
- t = stack.pop()
- ret.append(t.val)
- root = t.right
- return ret
Python实现二叉树的非递归中序遍历
来源: http://www.bubuko.com/infodetail-2396337.html