题目如下:

【leetcode】589. 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

 

相关文章:

  • 2022-12-23
  • 2021-09-22
  • 2021-06-28
  • 2021-10-04
  • 2022-02-10
  • 2021-06-28
  • 2021-12-15
  • 2021-09-27
猜你喜欢
  • 2021-09-16
  • 2021-10-24
  • 2021-11-16
  • 2022-12-23
  • 2021-07-28
  • 2021-07-26
  • 2021-10-15
相关资源
相似解决方案