Post-order Traversal Of Binary T
2018-04-24 本文已影响0人
GakkiLove
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)