首页 > 其他 > 详细

【leetcode】589. N-ary Tree Preorder Traversal

时间:2018-07-31 20:18:48      阅读:196      评论:0      收藏:0      [点我收藏+]

题目如下:

技术分享图片

解题思路:凑数题+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

 

【leetcode】589. N-ary Tree Preorder Traversal

原文:https://www.cnblogs.com/seyjs/p/9397650.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!