题目要求

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. Android Studio 运行出现 Multiple dex files define Landroid/support/annotation/AnimRes 解决方法

    引入的工程的android-support-v4.jar版本跟自己工程的android-support-v4.jar的版本不一样

  2. 【Matplotlib】利用Python进行绘图

    [Matplotlib] 教程:https://morvanzhou.github.io/tutorials/data-manipulation/plt/ 官方文档:https://matplotli ...

  3. iTunes空间不足无法备份iphone的问题

    因为换手机,需要把旧iphone备份出来,在新iphone上恢复.使用mac进行备份时总是提示iTunes无法备份,所用电脑空间不够,即使有个用空间的移动硬盘也无法备份.网上的方法都是说修改iTune ...

  4. @Transactional(rollbackFor = Exception.class)

    @Transactional(rollbackFor = Exception.class)这个注解只有在出异常时才会回滚,需要回滚时没有异常也要人为制造异常(自定义异常)所以,如果使用了异常捕获,很有 ...

  5. Go指南_切片的长度与容量

    源地址 https://tour.go-zh.org/moretypes/11 一.描述 切片拥有 长度 和 容量. 切片的长度就是它所包含的元素个数. 切片的容量是从它的第一个元素开始数,到其底层数 ...

  6. Nginx 基本命令

    基础命令 1.启动 直接点击Nginx目录下的nginx.exe 或者 cmd运行start nginx 2.关闭 nginx -s stop 或者 nginx -s quit stop表示立即停止n ...

  7. java-信息安全(十二)-数字签名【Java证书体系实现】

    概述 信息安全基本概念 数字证书 数字证书就是互联网通讯中标志通讯各方身份信息的一串数字,提供了一种在Internet上验证通信实体身份的方式,数字证书不是数字身份证,而是身份认证机构盖在数字身份证上 ...

  8. ABBYY FineReader 12如何识别包含非常规符号的文本

    ABBYY FineReader 12 是一款OCR图文识别软件,可快速方便地将扫描纸质文档.PDF文件和数码相机的图像转换成可编辑.可搜索的文本,有时文本中可能会包含一些非常规的符号,此时ABBYY ...

  9. PHP_CodeSniffer HG 服务端部署篇

    环境:CentOs 6.7 语言:PHP5.4 PHP_CodeSniffer: https://github.com/phpdragon/PHP_CodeSniffer 本地代码检测请查看该文章:h ...

  10. Zookeeper安装使用及JavaAPI使用

    一.Zookeeper单击模式安装及使用 1.系统环境 2.导入JDK和Zookeeper包 1).使用SecureCRT工具打开SFTP连接,直接拖拽,到当前用户文件夹下,然后使用mv命令(mv 文 ...