标签:set 图片 http efi end eee 分享图片 traversal rhel
1. Question
589. N-ary Tree Preorder Traversal
Given an n-ary tree, return the preorder traversal of its nodes‘ values.
For example, given a 3-ary
tree:
Return its preorder traversal as: [1,3,5,6,2,4]
.
2. Solution
# Definition for a Node. class Node(object): def __init__(self, val, children): self.val = val self.children = children class Solution(object): def preOrderHelp(self, root, path): if root is None: return path.append(root.val) children = root.children for ch in children: self.preOrderHelp(ch, path) def preorder(self, root): """ :type root: Node :rtype: List[int] """ re_li = [] self.preOrderHelp(root, re_li) return re_li
589. N-ary Tree Preorder Traversal
标签:set 图片 http efi end eee 分享图片 traversal rhel
原文地址:https://www.cnblogs.com/ordili/p/9974913.html