Leetcode no. 107
来源:互联网 发布:脸萌软件苹果版 编辑:程序博客网 时间:2024/06/16 01:52
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 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]]
/** * Definition for a binary tree node. * 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>> res= new LinkedList<>(); if (root== null) return res; level(res, 0, root); return res; } private void level(List<List<Integer>> list, int level, TreeNode root){ if (root== null) return; if (level>= list.size()) list.add(0, new LinkedList<>()); level(list, level+1, root.left); level(list, level+1, root.right); list.get(list.size()-level-1).add(root.val); }}
0 0
- Leetcode no. 107
- LeetCode No.11 ~No.12
- Leetcode NO.78 Subsets
- Leetcode NO.77 Combinations
- Leetcode NO.46 Permutations
- 【leetcode】No. 235 LCABST
- LeetCode no. 35
- Leetcode no. 37
- Leetcode no. 279
- Leetcode no. 335
- Leetcode no. 283
- Leetcode no. 181 (sql)
- Leetcode no. 40
- Leetcode no. 238
- Leetcode no. 26
- Leetcode no. 80
- Leetcode no. 228
- Leetcode no. 313
- 输入和输出函数
- 简单的java起步和面向对象说明
- sicily Catch the thief
- PHP大批量插入数据库的3种方法和速度对比
- java线程池基础知识
- Leetcode no. 107
- 毕业一年
- Labview实现AM调制
- hadoop2.0集群搭建笔记
- ICML论文|这违反直觉的“升噪”方法,反而能很好的解决激活函数梯度弥散的问题
- 通过了装饰器contextmanager实现的上下文管理器,
- js 克隆行、删除行
- Poj 2570 Fiber Network【Floyd+状态压缩】
- linux编译C++的cmake文件(CMakeList.txt)