# 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,null,null,15,7],

    3
/ \
9  20
/  \
15   7


return its bottom-up level order traversal as:

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

public class Solution {
public List<List<Integer>> levelOrderBottom(TreeNode root) {
int cnt = 0;
int f = 0;
int t = 1;
int index;
List<List<Integer>> lsts = new ArrayList<List<Integer>>();
List<Integer> lst = new ArrayList<Integer>();
List<TreeNode> nodeList = new ArrayList<TreeNode>();
if(root == null){
return 	lsts;
}
index = 0;
while(t != 0){
if(f == t){
t = cnt;
f = 0;
cnt = 0;
lst = new ArrayList<Integer>();
}
else{
TreeNode node = nodeList.get(index ++);
if(node != null){
f ++;
}
if(node.left != null){
cnt ++;
}
if(node.right != null){
cnt ++;
}
}
}
return 	lsts;
}
}

public class Solution {
public List<List<Integer>> levelOrderBottom(TreeNode root) {
int cnt = 0;
int f = 0;
int t = 1;
int index;
List<List<Integer>> lsts = new ArrayList<List<Integer>>();
List<Integer> lst = new ArrayList<Integer>();
List<TreeNode> nodeList = new ArrayList<TreeNode>();
if(root == null){
return 	lsts;
}
index = 0;
while(t != 0){
if(f == t){
t = cnt;
f = 0;
cnt = 0;
lst = new ArrayList<Integer>();
}
else{
TreeNode node = nodeList.get(index ++);
if(node != null){
f ++;
}
if(node.left != null){
cnt ++;
}
if(node.right != null){
cnt ++;
}
}
}
int from = 0,to = lsts.size() - 1;
while(from < to){
List<Integer> tempF = lsts.get(from);
List<Integer> tempE = lsts.get(to);
lsts.set(from, tempE);
lsts.set(to, tempF);
from ++;
to --;
}
return 	lsts;
}
}

        public List<List<Integer>> levelOrderBottom(TreeNode root) {
levelMaker(wrapList, root, 0);
return wrapList;
}

public void levelMaker(List<List<Integer>> list, TreeNode root, int level) {
if(root == null) return;
if(level >= list.size()) {
}
levelMaker(list, root.left, level+1);
levelMaker(list, root.right, level+1);
}

• 本文已收录于以下专栏：

## [LeetCode]Binary Tree Level Order Traversal II(JAVA)

• jsh0123
• 2016年09月14日 10:32
• 162

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

Binary Tree Level Order Traversal II [LeetCode] Given a binary tree, return the bottom-up level orde...

## [leetcode] 107. Binary Tree Level Order Traversal II

Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left...

## [LeetCode]--107. Binary Tree Level Order Traversal II

Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left...

## LeetCode 107. Binary Tree Level Order Traversal II

107. Binary Tree Level Order Traversal IIDescription Given a binary tree, return the bottom-up leve...

## Binary Tree Level Order Traversal II

/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; ...

## LeetCode 107. Binary Tree Level Order Traversal II 树的BFS、DFS

Binary Tree Level Order Traversal II 题意 思路 代码 BFS DFS107. Binary Tree Level Order Traversal II Giv...

## LeetCode 之 Binary Tree Level Order Traversal II

举报原因： 您举报文章：Binary Tree Level Order Traversal II 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)