# [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).

## 思路

ArrayList元素逆序，可以自己写个翻转的方法（双指针O(n)），也可以直接调用Collections类里的静态方法reverse

## AC代码

/**
* Definition for binary tree
* public class TreeNode {
*     int val;
*     TreeNode left;
*     TreeNode right;
*     TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public ArrayList<ArrayList<Integer>> levelOrderBottom(TreeNode root) {
ArrayList<ArrayList<Integer>> list = new ArrayList<ArrayList<Integer>>();
TreeNode p;

if (root == null) {
return list;
}

while (! queue.isEmpty()) {
ArrayList<Integer> sublist = new ArrayList<Integer>();

while (! queue.isEmpty()) {
p = queue.removeFirst();

if (p.left != null) {
}

if (p.right != null) {
}
}

}

Collections.reverse(list);
return list;
}
}

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

## 【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@Java解题报告

https://leetcode.com/problems/binary-tree-level-order-traversal-ii/description/ Given a b...

## Leetcode 103. Binary Tree Zigzag Level Order Traversal 二叉树Zigzag遍历 解题报告

1 解题思想首先这道题和 Leetcode 102. Binary Tree Level Order Traversal 二叉树按层遍历 解题报告 很接近，Zigzag同样是按层遍历，但是区别是对...
• MebiuW
• 2016年09月09日 12:26
• 782

## [leetcode]102. Binary Tree Level Order Traversal@Java解题报告

https://leetcode.com/problems/binary-tree-level-order-traversal/description/ Given a bina...

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

Binary Tree Level Order Traversal [LeetCode] Given a binary tree, return the level order traversal o...

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