Home N-ary Tree Postorder Traversal
Post
Cancel

N-ary Tree Postorder Traversal

Leetcode Problem

N-ary Tree Postorder Traversal

tree가 주어졌을 때, postorder 수행 결과를 구하는 문제입니다.

1
2
3
class Solution:
    def postorder(self, root: 'Node') -> List[int]:
        return sum([self.postorder(x) for x in root.children], []) + [root.val] if root else []

어제 배운 sum 함수를 활용했습니다.





참고

This post is licensed under CC BY 4.0 by the author.