[抄题]: 给定一个二叉树,像这样收集树节点:收集并移除所有叶子,重复,直到树为空. 给出一个二叉树: 1 / \ 2 3 / \ 4 5 返回 [[4, 5, 3], [2], [1]]. [暴力解法]: 时间分析: 空间分析: [思维问题]: 觉得要用BFS.不知道用dfs怎么求高度:max(左,右)+1,这是高度的定义吧 只知道怎么摘,不知道要去尝试用数学表示出来:第k层扒下来的叶子节点,高度也是k 不知道怎么把一层的节点都存在一个hashmap中,觉得一个key不是只能存一个value么…
102. 二叉树的层次遍历 102. Binary Tree Level Order Traversal 题目描述 给定一个二叉树,返回其按层次遍历的节点值. (即逐层地,从左到右访问所有节点). 每日一算法2019/5/11Day 8LeetCode102. Binary Tree Level Order Traversal 例如: 给定二叉树: [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 返回其层次遍历结果: [ [3], [9,20], [15…
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example:Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 return its level order traversal as: [ [3], [9,20], [15,7…
[抄题]: 给出一棵二叉树,返回其节点值的层次遍历(逐层从左往右访问) [思维问题]: [一句话思路]: 用queue存每一层 [输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入): [画图]: [一刷]: 每一层level存的东西都是不一样的,所以要在queue非空的循环中再新建.不要当成全局变量. root为空时,返回result空数组,而不是null四个字母 stack用pop 弹出来,queue用poll 拉出来,想想也比较形象.root非空用n…
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 or…
[抄题]: 给定二叉树,返回其节点值的垂直遍历顺序. (即逐列从上到下).如果两个节点在同一行和同一列中,则顺序应 从左到右. 给定一个二叉树 {3,9,20,#,#,15,7} 3 /\ / \ 9 20 /\ / \ 15 7 返回垂直遍历顺序:[[9],[3,15],[20],[7]] 给定一个二叉树 {3,9,20,#,#,15,7} 3 /\ / \ 9 8 /\ /\ / \/ \ 4 01 7 返回垂直遍历顺序:[[4],[9],[3,0,1],[8],[7]] [暴力解法]: 时…
Given a binary tree, return the vertical order traversal of its nodes' values. (ie, from top to bottom, column by column). If two nodes are in the same row and column, the order should be from left to right. Examples:Given binary tree [3,9,20,null,nu…
翻译 给定一个二叉树,返回从下往上遍历经过的每一个节点的值. 从左往右,从叶子到节点. 比如: 给定的二叉树是 {3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7 返回它从下往上的遍历结果: [ [15,7], [9,20], [3] ] 原文 Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, lev…
Given a binary tree, return the vertical order traversal of its nodes' values. (ie, from top to bottom, column by column). If two nodes are in the same row and column, the order should be from left to right. Examples: Given binary tree [3,9,20,null,n…
Binary Tree Level Order Traversal 题目描述: Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7 return its level order…