题目

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]
]

myanswer:

只需在102. Binary Tree Level Order Traversal改动一行即可

class Solution:def levelOrderBottom(self, root):""":type root: TreeNode:rtype: List[List[int]]"""if not root:return []res, level = [],[root]while level:currentNode = []nextLevel = []for node in level:currentNode.append(node.val)if node.left:nextLevel.append(node.left)if node.right:nextLevel.append(node.right)res.insert(0, currentNode)   # 每次都给插入到列表的头部level = nextLevelreturn res

107. Binary Tree Level Order Traversal II相关推荐

  1. LeetCode 107. Binary Tree Level Order Traversal II

    LeetCode 107. Binary Tree Level Order Traversal II Solution1:我的答案 比102那道题多了一行代码... /*** Definition f ...

  2. 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 l ...

  3. Leet Code OJ 107. Binary Tree Level Order Traversal II [Difficulty: Easy]

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

  4. [Leetcode]@python 107. Binary Tree Level Order Traversal II

    题目链接 https://leetcode.com/problems/binary-tree-level-order-traversal-ii/ 题目原文 Given a binary tree, r ...

  5. Leetcode | 107. Binary Tree Level Order Traversal II

    题目:二叉树的层次遍历 II 1. 代码①:深度优先搜索(链接) /*** Definition for a binary tree node.* struct TreeNode {* int val ...

  6. 利用bds和dfs解决 LeetCode 107. Binary Tree Level Order Traversal II

    问题简述 给定一棵二叉树,返回该二叉树自底向上遍历的结点值(即从左到右,自底向上) 比如给定一颗二叉树 [3,9,20,null,null,15,7] 3/ \ 9 20/ \ 15 7 返回的结果为 ...

  7. Binary Tree Level Order Traversal II 解题思路

    思路: 与Binary Tree Level Order Traversal I 几乎一样.只是最后将结果存放在栈里,然后在栈里再传给向量即可. 再次总结思路: 两个queue,先把第一个放进q1,循 ...

  8. Binary Tree Level Order Traversal II leetcode java

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

  9. leetcode 二叉树的层次遍历 II(Binary Tree Level Order Traversal II)

    目录 题目描述: 示例: 解法: 题目描述: 给定一个二叉树,返回其节点值自底向上的层次遍历. (即按从叶子节点所在层到根节点所在的层,逐层从左向右遍历) 示例: 给定二叉树 [3,9,20,null ...

最新文章

  1. MySQL安装ODBC驱动出现126错误
  2. 使用非常驻任务管理事件
  3. 写一个程序,用于分析一个字符串中各个单词出现的频率,并将单词和它出现的频率输出显示。(单词之间用空格隔开,如“Hello World My First Unit Test”);...
  4. 谈谈利用JavaScript结合相对单位rem实现自适应布局的简单而实用的方法
  5. 20应用统计考研复试要点(part39)--概率论与数理统计
  6. AdminLTE 3.0发布了
  7. python歌星大奖赛_在歌星大奖赛中,有10个评委为参赛选手打分,分数为1到100分。...
  8. linux 系统课程-进程控制01
  9. FreeSql (八)插入数据时指定列
  10. 自动清除html无用css,TinyMCE粘贴HTML代码,避免style属性被自动清除_html/css_WEB-ITnose...
  11. Windows 系统下安装anaconda教程 ,小白教程!!!
  12. 浅谈FOF场外投资交易流程
  13. 【QT】基于HTTP通信的天气查询的实现
  14. 金蝶kis专业版公网访问_金蝶KIS远程服务器端和远程客户端配置说明
  15. txt音乐播放器PC版免费下载(包含C程序源码与exe文件)
  16. PCB需要清洗的技巧
  17. Unity3D Delegate
  18. circos 可视化手册- text 篇
  19. Android中将像素转换为sp/dp
  20. 计算机信息计量单位G的单位,计算机中的有些计量单位例如G、MB是表示什么意思?...

热门文章

  1. 【golang程序包推荐分享】分享亿点点golang json操作及myJsonMarshal程序包开发的踩坑经历 :)
  2. jdk12‘javac‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件。
  3. Mysql生成UUID
  4. pandas dataframe 字符映射为数字
  5. 操作系统学习笔记 第一章:操作系统概述(王道考研)
  6. 王道考研 计算机网络笔记 第二章:物理层
  7. GPU自动调度卷积层
  8. 用NVIDIA-TensorRT构造深度神经网络
  9. 自动泊车技术短暂困境,前景可期
  10. 自动驾驶的分级和行业现状