트리순회11 [알고리즘] Tree Traversal - Depth First Traversal Depth First Traversal로 진행되는 트리 순회는 - preorder(root-> left -> right) - inorder(left->root->right) - postorder(left->right->root) 가 존재한다. www.geeksforgeeks.org/tree-traversals-inorder-preorder-and-postorder/ Tree Traversals (Inorder, Preorder and Postorder) - GeeksforGeeks A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programmin.. 2020. 10. 4. [leetcode 94] Binary Tree Inorder Traversal Example 1: Input: root = [1,null,2,3] Output: [1,3,2] Example 2: Input: root = [] Output: [] Example 3: Input: root = [1] Output: [1] 1) recursive 풀이 class Solution { public: void Recursive(TreeNode* root, vector &answer){ if(root == nullptr){ return; } Recursive(root->left, answer); answer.push_back(root->val); Recursive(root->right, answer); } vector inorderTraversal(TreeNode* root) { vector a.. 2020. 10. 4. [leetcode 993] Cousins in Binary Tree - 두 노드가 부모가 다르고 같은 depth를 가진 cousin인지 확인하기 In a binary tree, the root node is at depth 0, and children of each depth k node are at depth k+1. Two nodes of a binary tree are cousins if they have the same depth, but have different parents. We are given the root of a binary tree with unique values, and the values x and y of two different nodes in the tree. Return true if and only if the nodes corre.. 2020. 10. 3. 이전 1 2 3 다음