题目要求

Given an n-ary tree, return the postorder traversal of its nodes' values.

题目分析及思路

题目给出一棵N叉树,要求返回结点值的后序遍历。可以使用递归的方法做。因为是后序遍历,所以最后加入根结点的值。

python代码​

"""

# Definition for a Node.

class Node:

def __init__(self, val, children):

self.val = val

self.children = children

"""

class Solution:

def postorder(self, root):

"""

:type root: Node

:rtype: List[int]

"""

order = []

if not root:

return order

for child in root.children:

order.extend(self.postorder(child))

order.append(root.val)

return order

LeetCode 590 N-ary Tree Postorder Traversal 解题报告的更多相关文章

  1. 【LeetCode】145. Binary Tree Postorder Traversal 解题报告 (C++&Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 迭代 日期 题目地址:https://leetc ...

  2. LeetCode: Binary Tree Postorder Traversal 解题报告

    Binary Tree Postorder Traversal Given a binary tree, return the postorder traversal of its nodes' va ...

  3. 【LeetCode】590. N-ary Tree Postorder Traversal 解题报告 (C++&Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 迭代 相似题目 参考资料 日期 题目地址:htt ...

  4. 【LeetCode】144. Binary Tree Preorder Traversal 解题报告(Python&C++&Java)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 迭代 日期 题目地址:https://leetc ...

  5. 【LeetCode】94. Binary Tree Inorder Traversal 解题报告(Python&C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 递归 迭代 日期 题目地址:https://leetcode.c ...

  6. 【LeetCode】589. N-ary Tree Preorder Traversal 解题报告 (Python&C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 迭代 日期 题目地址:https://leetc ...

  7. 【LeetCode】106. Construct Binary Tree from Inorder and Postorder Traversal 解题报告

    [LeetCode]106. Construct Binary Tree from Inorder and Postorder Traversal 解题报告(Python) 标签: LeetCode ...

  8. 【LeetCode】145. Binary Tree Postorder Traversal (3 solutions)

    Binary Tree Postorder Traversal Given a binary tree, return the postorder traversal of its nodes' va ...

  9. LeetCode: Construct Binary Tree from Inorder and Postorder Traversal 解题报告

    Construct Binary Tree from Inorder and Postorder Traversal Given inorder and postorder traversal of ...

随机推荐

  1. JAVA(二)异常/包及访问权限/多线程/泛型

    成鹏致远 | lcw.cnblog.com |2014-01-28 异常 1.异常的基本概念 异常是导致程序中断运行的一种指令流 基本的异常处理格式:try...catch,try中捕获异常,出现异常 ...

  2. Ubuntu 卸载重装 IntelliJ Idea Community

    参考: https://stackoverflow.com/questions/22983101/how-to-uninstall-intellij-idea-on-ubuntu-13-10 @SLH ...

  3. [INS-20802] Oracle Net Configuration Assistant failed

    [INS-20802] Oracle Net Configuration Assistant failed.在安装Oracle 11g R2时出现了该错误提示.以前安装的时候没有碰到过类似的错误.原来 ...

  4. 【iCore4 双核心板_ARM】例程二十一:LWIP_TCP_SERVER实验——以太网数据传输

    实验现象: 核心代码: int main(void) { system_clock.initialize(); led.initialize(); adc.initialize(); delay.in ...

  5. Godot游戏引擎 3.0 Beta2 于12月21日发布

    Beta版继续在修复bug.其官方表示原计划在今年的圣诞节发布3.0 Stable版的,但看来只能继续跳票. 由于开发力量比较单薄,新版本的开发进展算是比较慢的,但3.0这个版本值得期待. Godot ...

  6. Git 藏匿操作

    假设您正在为您的产品实施的一项新功能.你的代码是在推进开发进度而客户不断升级需求突然来了.正因为如此,你必须保持放下你的新功能,工作几个小时.你不能提交你的部分代码,也不能扔掉你的变化.所以,你需要一 ...

  7. jquery checkbox checked 却不显示对勾

    $("input").attr("checked", true); 或 $("input").attr("checked" ...

  8. 对TextFile格式文件的lzo压缩建立index索引

    转自:http://blog.csdn.net/yangbutao/article/details/8519572 hadoop中可以对文件进行压缩,可以采用gzip.lzo.snappy等压缩算法. ...

  9. Linux磁盘概念及其管理工具fdisk

    Linux磁盘概念及其管理工具fdisk [日期:2016-08-27] 来源:Linux社区  作者:chawan [字体:大 中 小]   引言:冯诺依曼体系中的数据存储器就是我们常说的磁盘或硬盘 ...

  10. Java8学习笔记(二)--三个预定义函数接口

    三个函数接口概述 JDK预定义了很多函数接口以避免用户重复定义.最典型的是Function: @FunctionalInterface public interface Function<T, ...