题目要求

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. ABAP 内表(internal table) 标题行(header line) 工作区(work area) 简介 - [SAP]

    刚开始学ABAP的时候,学到iternal table时,感觉一阵混乱.搞不清楚什么是work area,什么是header line,以及occurs是干什么用的.今天终于差不多搞明白了(我还是太弱 ...

  2. Java中内存溢出与内存泄露

    内存溢出 内存溢出(out of memory),是指程序在申请内存时,没有足够的内存空间供其使用,出现out of memory:比如申请了一个integer,但给他存了long才能存下的数,就会发 ...

  3. android——判断当前网络是否可用

    http://www.cnblogs.com/codeworker/archive/2012/04/23/2467180.html //判断当前是否有网络连接 private boolean isCo ...

  4. 【转】Windows下charles 使用教程指南

    1.下载就不用再说了,网上好多破解的安装包 2.下面是pc端的抓包使用情况 Charles支持抓去http.https协议的请求,不支持socket.然后charles会自动配置IE浏览器和工具的代理 ...

  5. 设置gem源,解决下载慢的问题

    问题解决的最好方法方法 使用google的DNS 8.8.8.8 / 8.8.4.4 另一种解决方式 修改rubygems的source源 $ gem source -r http://rubygem ...

  6. Scala学习笔记(一):入门

    变量定义 Scala有两种变量,val和var.val类似于Java中的final变量,一旦初始化了,val就不能再被赋值.var可以多次赋值.但由于函数式编程特性,Scala更推崇val. var的 ...

  7. Redhat6.5——解决yum功能不能正常使用

    以前或多或少接触过linux服务器,由于是服务器上的,很多东西也没去玩过.要想多研究,还是得自己弄一个linux系统.由于正常工作,还是接触windows更多,双系统显然没有那么方便,所以决定弄个虚拟 ...

  8. AES和RSA算法的demo代码

    aes代码示例: package com.autoyol.util.security.test; import java.security.Key; import java.security.NoSu ...

  9. [PHP] 09 - PHP 7 & Tricky

    新特征列表: 序号 内容 1 PHP 标量类型与返回值类型声明 2 PHP NULL 合并运算符 3 PHP 太空船运算符(组合比较符) 4 PHP 常量数组 5 PHP 匿名类 6 PHP Clos ...

  10. java.util.HashMap的简单介绍

    1. java.util.HashMap的底层实现是数组+链表. 2. 简介put(key, value)方法的执行过程: 1)通过key值,使用散列算法计算出来一个hash值,用来确定该元素需要存储 ...