class Solution:
def preorder(self, root: 'Node', ans: list = None) -> List[int]:
if not root:
return ans
if ans == None:
ans = []
ans.append(root.val)
for child in root.children:
self.preorder(child, ans)
return ans
'Python 문제풀이 > LeetCode' 카테고리의 다른 글
98. Validate Binary Search Tree ** (트리 왼,오 비교 ?? ) (0) | 2022.08.22 |
---|---|
102. Binary Tree Level Order Traversal ** (BFS 사용) (0) | 2022.08.22 |
13. Roman to Integer (0) | 2022.08.16 |
409. Longest Palindrome (0) | 2022.08.16 |
142. Linked List Cycle II ** (플루이드 순환 탐지 알고리즘) (0) | 2022.08.16 |