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. git push远程仓库时报错:fatal: remote origin already exists. (已解决)

    在做远程仓库调试阶段,突然发现修改后的项目无法push了: 如果输入$ git remote add origin git@github.com:djqiang(github帐号名)/gitdemo( ...

  2. jedis、jedisPool、jedisCluster的使用方法

    jedis 连接redis(单机): 使用jedis如何操作redis,但是其实方法是跟redis的操作大部分是相对应的. 所有的redis命令都对应jedis的一个方法     1.在macen工程 ...

  3. java.lang.IllegalStateException: Mapped class was not specified

    错误如下:java.lang.IllegalStateException: Mapped class was not specifiedat org.springframework.util.Asse ...

  4. C语言各类型大小,结构体大小 sizeof(struct A)

    C语言类型大小总览 编译器pack指令 #pragma pack(n)——定义n字节对齐 C++固有类型的对齐取编译器对齐与自身大小中较小的一个 32位C++默认8字节对齐.gcc编译器默认4字节对齐 ...

  5. java jvm概述及工作过程中的内存管理

    java jvm 有分层的思想.   java类..java文件,源文件,源代码,源程序   编译器不能把源代码直接编译成0101,除非是java语言写的操作系统.   windows认识的可执行文件 ...

  6. GIT速成

    安装工具与使用工具: GIT工具 :https://www.git-scm.com/download/ WINGDOWS图形界面工具:https://download.tortoisegit.org/ ...

  7. BootStrap selectpicker后台动态绑定数据

    项目使用BootStrap设置select时,不能动态加载,使用以下方法可以解决. //获得全部订单信息(订单ID,订单名称) function GetAllOrders(obj) { $.ajax( ...

  8. react的基本概念

    数据流向 数据的改变发生通常是通过用户交互行为或者浏览器行为(如路由跳转等)触发的,当此类行为会改变数据的时候可以通过 dispatch 发起一个 action,如果是同步行为会直接通过 Reduce ...

  9. leetcode 之 Degree of an Array

    1.题目描述 Given a non-empty array of non-negative integers nums, the degree of this array is defined as ...

  10. 自己搭建anki服务器

    目录 centos端 电脑客户端 安卓端 centos端 # 安装服务 yum -y install python-setuptools easy_install Ankiserver mkdir - ...