[LeetCode 589. N-ary Tree Preorder Traversal ] Python 트리 구조 기초
Algorithm/LeetCode 문제 풀이 2019. 5. 1. 19:58파이썬 그리고 트리에 익숙해지기
"""
# Definition for a Node.
class Node:
def __init__(self, val, children):
self.val = val
self.children = children
"""
class Solution:
def preorder(self, root: 'Node') -> List[int]:
if not root:
return []
traversal = [root.val]
for child in root.children:
traversal.extend(self.preorder(child))
return traversal
-> 뒤에 나오는 것은 리턴 타입이다
즉 List[int] 가 리턴 타입
'Algorithm > LeetCode 문제 풀이' 카테고리의 다른 글
[LeetCode 144. Binary Tree Preorder Traversal] Python 트리 기초 preorder (0) | 2019.05.03 |
---|---|
[LeetCode 94. Binary Tree Inorder Traversal] Inorder Tree 구조 (0) | 2019.05.01 |
[LeetCode 130. Surrounded Regions] C++, Java (0) | 2019.04.09 |
[LeetCode 200. Number of Islands] C++ , C++로 전향하기로 결정했다. (0) | 2019.04.03 |
[Leetcode 492. Construct the Rectangle] Java (0) | 2019.04.02 |