python


  • 0
    S

    class Solution(object):
    def postorderTraversal(self, root):
    """
    :type root: TreeNode
    :rtype: List[int]
    """
    stack = []
    res = []
    while root:
    stack.append(root)
    root = root.left
    while stack:
    if not stack[-1].right:
    res.append(stack.pop().val)
    else:
    node = stack[-1].right
    stack[-1].right = None
    stack.append(node)
    while node.left:
    stack.append(node.left)
    node = node.left
    return res


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.