做完这道题,只能说基本功很重要,数组中套数组就不会用了,过几天吧1做了,看自己到底等没。

https://oj.leetcode.com/problems/binary-tree-level-order-traversal-ii/

import java.util.*;
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/ public class Solution {
public List<List<Integer>> levelOrderBottom(TreeNode root) {
// List<List<Integer>> list=new ArrayList<ArrayList<Integer>>();
ArrayList<ArrayList<Integer>> list = new ArrayList<ArrayList<Integer>>();
if(root==null) return (List)list; Queue<TreeNode> q=new LinkedList<TreeNode>();
q.offer(root);
while(!q.isEmpty())
{
ArrayList<Integer> temp=new ArrayList<Integer>();
int len=q.size(); for(int i=0;i<len;i++)
{
TreeNode t=q.poll();
temp.add(t.val);
if(t.left!=null) q.offer(t.left); if(t.right!=null) q.offer(t.right);
} ArrayList<Integer> arry2=new ArrayList<Integer>(temp);
list.add(arry2);
temp.clear(); }
int n=list.size(); for(int i=0;i<n/2;i++)
{
ArrayList temp=list.get(i);
list.set(i,list.get(n-1-i)); list.set(n-i-1,temp);
//swap } return (List)list; }
}

  

leecode Binary Tree Level Order Traversal II java的更多相关文章

  1. leetcode 107 Binary Tree Level Order Traversal II ----- java

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

  2. LeetCode_107. Binary Tree Level Order Traversal II

    107. Binary Tree Level Order Traversal II Easy Given a binary tree, return the bottom-up level order ...

  3. 35. Binary Tree Level Order Traversal && Binary Tree Level Order Traversal II

    Binary Tree Level Order Traversal OJ: https://oj.leetcode.com/problems/binary-tree-level-order-trave ...

  4. Binary Tree Level Order Traversal,Binary Tree Level Order Traversal II

    Binary Tree Level Order Traversal Total Accepted: 79463 Total Submissions: 259292 Difficulty: Easy G ...

  5. LeetCode之“树”:Binary Tree Level Order Traversal && Binary Tree Level Order Traversal II

    Binary Tree Level Order Traversal 题目链接 题目要求: Given a binary tree, return the level order traversal o ...

  6. 102/107. Binary Tree Level Order Traversal/II

    原文题目: 102. Binary Tree Level Order Traversal 107. Binary Tree Level Order Traversal II 读题: 102. 层序遍历 ...

  7. 【LeetCode】107. Binary Tree Level Order Traversal II (2 solutions)

    Binary Tree Level Order Traversal II Given a binary tree, return the bottom-up level order traversal ...

  8. 63. Binary Tree Level Order Traversal II

    Binary Tree Level Order Traversal II My Submissions QuestionEditorial Solution Total Accepted: 79742 ...

  9. Java for 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 ...

随机推荐

  1. HDU 4706 Children's Day(简单模拟)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4706 题目大意:要用‘a’-‘z’ 26个小写字母输出倒着写得字母'N'的形状,例如 a ebdfc ...

  2. Codevs 5208 求乘方取模

    5208 求乘方取模 时间限制: 1 s 空间限制: 1000 KB 题目等级 : 未定级 题目描述 Description 给定非负整数A.B.M,求(A ^ B) mod M. 输入描述 Inpu ...

  3. 配置trac

    1. enable apache mod_auth_digest 2. 设置Location

  4. dom 笔记

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. markdown与textile之间互相转换

    markdown与textile之间互相转换 redmine中默认使用的是textile那么从别的地方复制过来的markdown格式的内容需要进行转换 找到一款工具叫做pandoc http://jo ...

  6. php练习2——乘法表,变量的使用

    目标:输出九九乘法表 程序: 结果: 目标: 程序variable01.html和variable01.php 结果:

  7. 一个PDO类

    下面是在网上借鉴的一个PDO类: <?php class Database{ private $host = DB_HOST; private $user = DB_USER; private ...

  8. wpf RadioButton控件的一个bug,onpropertychanged后会修改旧属性的值

    测试代码下载:http://files.cnblogs.com/djangochina/RadioButtonBug.zip 从上面列表选择不同的行,再设置下面不同的radiobutton看看结果 b ...

  9. WiFi无线模块学习1——HLK-M30使用

    产品概述 概述: 通过该模块,传统的串口设备在不需要更改任何配置的情况下,即可通过Internet 网络传输自己的数据.为用户的串口设备提供完整快读的解决方案. 技术参数 可查询技术规格表 主要应用领 ...

  10. 深入浅出Z-Stack 2006 OSAL多任务资源分配机制

    转自深入浅出Z-Stack 2006 OSAL多任务资源分配机制 一.概述 OSAL (Operating System Abstraction Layer),翻译为"操作系统抽象层&quo ...