美文网首页
Post-order Traversal Of Binary T

Post-order Traversal Of Binary T

作者: GakkiLove | 来源:发表于2018-04-24 21:01 被阅读0次

Implement an iterative, post-order traversal of a given binary tree, return the list of keys of each node in the tree as it is post-order traversed.

Examples

        5

      /    \

    3        8

  /   \        \

1      4        11

Post-order traversal is [1, 4, 3, 11, 8, 5]

class Solution(object):
  def postOrder(self, root):
    if not root:
      return []
    res = []
    self.helper(root,res)
    return res
  
  def helper(self,root,res):
    if not root:
      return
    self.helper(root.left,res)
    self.helper(root.right,res)
    res.append(root.val)

相关文章

网友评论

      本文标题:Post-order Traversal Of Binary T

      本文链接:https://www.haomeiwen.com/subject/curslftx.html