【Leetcode】Binary Tree Level Order Traversal II

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,#,#,15,7},

    3
/ \
9  20
/  \
15   7


return its bottom-up level order traversal as:

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


	public List<List<Integer>> levelOrderBottom(TreeNode root) {
int height = heightTree(root);
List<List<Integer>> lists = new ArrayList<List<Integer>>();
for (int i = height; i > 0; i--) { //自下而上
List<Integer> list = new ArrayList<Integer>();
list = kLevelNumber(root, 1, list, i);
}
return lists;
}

public int heightTree(TreeNode p) {
if (p == null)
return 0;
int h1 = heightTree(p.left);
int h2 = heightTree(p.right);
return h1 > h2 ? h1 + 1 : h2 + 1;
}

/**
* 返回kk层所有结点
*/
public List<Integer> kLevelNumber(TreeNode p, int height, List<Integer> list, int kk) {
if (p != null) {
if (height == kk) {
}
list = kLevelNumber(p.left, height + 1, list, kk);
list = kLevelNumber(p.right, height + 1, list, kk);
}
return list;
}

LeetCode 107:Binary Tree Level Order Traversal II

2015-05-31 00:11:23

【LeetCode】107. Binary Tree Level Order Traversal II 解题报告

2016-05-26 16:18:51

LeetCode --- 107. Binary Tree Level Order Traversal II

2015-04-17 16:46:33

leetcode 107 Binary Tree Level Order Traversal II C++

2016-05-28 20:57:50

[LeetCode] Binary Tree Level Order Traversal 二叉树层次遍历(DFS | BFS)

2015-09-11 02:20:37

leetCode解题报告之Binary Tree Level Order Traversal II,I(二叉树层次遍历)

2014-03-28 20:28:01

[LeetCode 107]Binary Tree Level Order Traversal II(递归法）

2016-07-24 17:39:08

LeetCode102 Binary Tree Level Order Traversal Java

2016-04-23 14:20:55

【LeetCode】102. Binary Tree Level Order Traversal 解题报告

2016-05-26 15:06:54

leetcode 之Binary Tree Level Order Traversal I和II 解题思路

2014-07-11 23:43:09