590. N-ary Tree Postorder Traversal

自己没写出来
 
优秀代码:
"""
# Definition for a Node.
class Node(object):
def __init__(self, val, children):
self.val = val
self.children = children
"""
class Solution(object):
def postorder(self, root):
"""
:type root: Node
:rtype: List[int]
"""
res=[]
if root==None:
return res
stack=[root]
while stack:
curr=stack.pop()
res.append(curr.val)
stack.extend(curr.children)
return res[::-1]

反思:1.列表的常见操作不熟悉

  2.怎么用list来处理树结构,不知道

strategy:

1.用anki记忆一些list的常见操作

2.知道迭代和递归的区别

Leetcode590. N-ary Tree Postorder Traversal的更多相关文章

  1. LeetCode 590. N叉树的后序遍历(N-ary Tree Postorder Traversal)

    590. N叉树的后序遍历 590. N-ary Tree Postorder Traversal 题目描述 给定一个 N 叉树,返回其节点值的后序遍历. LeetCode590. N-ary Tre ...

  2. 12. Binary Tree Postorder Traversal && Binary Tree Preorder Traversal

    详见:剑指 Offer 题目汇总索引:第6题 Binary Tree Postorder Traversal            Given a binary tree, return the po ...

  3. Binary Tree Preorder Traversal and Binary Tree Postorder Traversal

    Binary Tree Preorder Traversal Given a binary tree, return the preorder traversal of its nodes' valu ...

  4. [LeetCode] N-ary Tree Postorder Traversal N叉树的后序遍历

    Given an n-ary tree, return the postorder traversal of its nodes' values. For example, given a 3-ary ...

  5. C++版 - LeetCode 145: Binary Tree Postorder Traversal(二叉树的后序遍历,迭代法)

    145. Binary Tree Postorder Traversal Total Submissions: 271797 Difficulty: Hard 提交网址: https://leetco ...

  6. LeetCode:145_Binary Tree Postorder Traversal | 二叉树后序遍历 | Hard

    题目:Binary Tree Postorder Traversal 二叉树的后序遍历,题目要求是采用非递归的方式,这个在上数据结构的课时已经很清楚了,二叉树的非递归遍历不管采用何种方式,都需要用到栈 ...

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

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

  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. 二叉树前序、中序、后序非递归遍历 144. Binary Tree Preorder Traversal 、 94. Binary Tree Inorder Traversal 、145. Binary Tree Postorder Traversal 、173. Binary Search Tree Iterator

    144. Binary Tree Preorder Traversal 前序的非递归遍历:用堆来实现 如果把这个代码改成先向堆存储左节点再存储右节点,就变成了每一行从右向左打印 如果用队列替代堆,并且 ...

随机推荐

  1. 不同CSS布局实现与文字鼠标选择的可用性——张鑫旭

    by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=2401 一.文字选择的 ...

  2. HTML5和IOS、Android之间的交互

    HTML5向IOS.Android传参: html给native传参需要注意三点: 1.判断终端设备,一般我们都是双系统开发,android和ios语言又不一样:我们需要用不同的方法给他们传递参数: ...

  3. 基于OpenMP的C++并行编程简单示例

    示例要求:在整数A和B之间找到符合条件的值X,使f(X)=C. 示例代码(需要在VS中开启OpenMP支持): #include<iostream> #include<time.h& ...

  4. java 内存分析之方法返回值二

    package Demo; class Point { private double x, y; public Point(double x, double y) { this.x = x; this ...

  5. justreq测试接口配置服务

    特性 自动缓存每一次接口请求,当测试服务器宕机时,依然可以从容开发 接口替身服务,当后台GG们还没开发好接口时,可以用json.txt等替代 独有jrs脚本,仿php,可以定制更灵活的接口替身,甚至可 ...

  6. 在ubuntu中用apt-get安装LEMP栈(linux+nginx+mysql+php)

    在ubuntu上安装lamp大家应该都很熟悉了,但对于现在很流行的lemp栈怎么样用apt-get安装,这样介绍的文章的不多.下面我用Ubuntu 12.04 LTS为例来介绍下如何用apt-get安 ...

  7. 如何将同一 VNET 下的虚拟机从经典部署模型迁移到 Azure Resource Manager

    本文内容 适用场景 解决方案 适用场景 用户拥有多个云服务但是在同一个 VNET 下,希望将这些虚拟机从经典部署模型(以下简称:ASM)迁移到 Azure Resource Manager(以下简称: ...

  8. C#实体类对象修改日志记录

    C#实体类对象修改日志记录 类型验证帮助类 public static class TypeExtensions { public static bool InheritsFrom(this Type ...

  9. sql建JOB语句

    declare job_id pls_integer; begin sys.dbms_job.submit(job => job_id, what => 'proc_AGTAWBSTATI ...

  10. 渐变显示渐变消失的BackgroundView

    渐变显示渐变消失的BackgroundView 效果如下: 源码: BackgroundView.h 与 BackgroundView.m // // BackgroundView.h // Test ...