标签:分享 lis order ret pytho object span .com center
一、题目描述
给定一个 N 叉树,返回其节点值的前序遍历
例如,给定一个3叉树:

"""
# Definition for a Node.
class Node(object):
def __init__(self, val, children):
self.val = val
self.children = children
"""
class Solution(object):
def preorder(self, root):
"""
:type root: Node
:rtype: List[int]
"""
if not root:
return []
result = [root.val]
for leaf in root.children:
result += self.preorder(leaf)
return result
标签:分享 lis order ret pytho object span .com center
原文地址:https://www.cnblogs.com/always-fight/p/10337242.html