Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).

For example:
Given binary tree [3,9,20,null,null,15,7],

    3
   / \
  9  20
    /  \
   15   7

 

return its bottom-up level order traversal as:

[
  [15,7],
  [9,20],
  [3]
]

 1 # Definition for a binary tree node.
 2 # class TreeNode(object):
 3 #     def __init__(self, x):
 4 #         self.val = x
 5 #         self.left = None
 6 #         self.right = None
 7 
 8 class Solution(object):
 9     def levelOrderBottom(self, root):
10         """
11         :type root: TreeNode
12         :rtype: List[List[int]]
13         """
14         answ, L = [], [root]
15         while L and root:
16             answ.insert(0,[n.val for n in L])
17             L = [ C for N in L for C in (N.left,N.right) if C ]
18         return answ

??????????

 

posted on 2017-03-15 18:57  Ci_pea  阅读(120)  评论(0编辑  收藏  举报