목록후위순회 (3)
넘치게 채우기
https://leetcode.com/problems/n-ary-tree-postorder-traversal/description/?envType=daily-question&envId=2024-08-26leetcode - N-ary Tree Postorder Traversal문제 유형 : 트리, dfs, 재귀, 스택문제 난이도 : Easy 문제Given the root of an n-ary tree, return the postorder traversal of its nodes' values.Nary-Tree input serialization is represented in their level order traversal. Each group of children is separated by the ..
https://leetcode.com/problems/count-nodes-equal-to-average-of-subtree/description/ Count Nodes Equal to Average of Subtree - LeetCode Can you solve this real interview question? Count Nodes Equal to Average of Subtree - Given the root of a binary tree, return the number of nodes where the value of the node is equal to the average of the values in its subtree. Note: * The average of n ele leetcod..
트리의 모든 노드들을 방문하는 과정을 트리의 순회라고 한다. 스택, 큐, 연결 리스트와 같은 선형 자료구조에서는 순차적으로 노드들을 방문하지만, 비선형 자료구조인 트리에서는 다음과 같은 재귀적인 방법들이 있다: 전위 순회(Preorder) 중위 순회(Inorder) 후위 순회(Postorder) 전위 순회 루트 → 왼쪽 서브트리 → 오른쪽 서브트리 순으로 순회. 코드 구현 def preorder_traversal(self, node): #전위 순회 print(node.data, end=" ") if node.left: self.preorder_traversal(node.left) if node.right: self.preorder_traversal(node.right) cs A B D E C F G cs..