Leetcode590. N-ary Tree Postorder Traversal

 

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.知道迭代和递归的区别

原文地址:https://www.cnblogs.com/captain-dl/p/10126239.html