leetcode589. N-ary Tree Preorder Traversal

Posted seyjs

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode589. N-ary Tree Preorder Traversal相关的知识,希望对你有一定的参考价值。

题目如下:

解题思路:凑数题+1,话说我这个也是凑数博?

代码如下:

class Solution(object):
    def preorder(self, root):
        """
        :type root: Node
        :rtype: List[int]
        """
        if root == None:
            return []
        res = []
        stack = [root]
        while len(stack) > 0:
            node = stack.pop(0)
            res.append(node.val)
            for i in node.children[::-1]:
                stack.insert(0,i)
        return res

 

以上是关于leetcode589. N-ary Tree Preorder Traversal的主要内容,如果未能解决你的问题,请参考以下文章

[LeetCode&Python] Problem 589. N-ary Tree Preorder Traversal

leetcode589. N-ary Tree Preorder Traversal

[LeetCode] 589. N-ary Tree Preorder Traversal_Easy

LeetCode 589. N叉树的前序遍历(N-ary Tree Preorder Traversal)

LeetCode 589 N-ary Tree Preorder Traversal 解题报告

[LeetCode] 589. N-ary Tree Preorder Traversal