목록이진트리 (9)
N
https://programmers.co.kr/learn/courses/30/lessons/42892?language=javascript 코딩테스트 연습 - 길 찾기 게임 [[5,3],[11,5],[13,3],[3,5],[6,1],[1,3],[8,6],[7,2],[2,2]] [[7,4,6,9,1,8,5,2,3],[9,6,5,8,1,4,3,2,7]] programmers.co.kr 이진 트리를 구성해 전위 순회와 후위순회를 한 결과를 리턴하는 문제. Node 라는 클래스를 정의하여 x, y, num, left, right를 가질 수 있도록 하였다. 이를 이용해 주어진 nodeinfo를 순회하여 노드를 만들어준다. node 라는 배열에 Node 클래스를 가진 node가 있으며, x와 y 좌표를 주어진 조건에..
https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=3&contestProbId=AWu1JmN6Js4DFASy&categoryId=AWu1JmN6Js4DFASy&categoryType=CODE&problemTitle=&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=3&pageSize=10&pageIndex=6 SW Expert Academy SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요! swexpertacademy.com 주어진 배열을 이진 트리의 중위 순회 방식으로 출력. K = depth를 뜻하므로, 배열의 원소를 방문하면서 count를 ..

226. Invert Binary Tree Given the root of a binary tree, invert the tree, and return its root. Example 1: Input: root = [4,2,7,1,3,6,9] Output: [4,7,2,9,6,3,1] Example 2: Input: root = [2,1,3] Output: [2,3,1] Example 3: Input: root = [] Output: [] Constraints: The number of nodes in the tree is in the range [0, 100]. -100 right); invertTree(root->left); invertTree(root->right); return root; } el..

145. Binary Tree Postorder Traversal Given the root of a binary tree, return the postorder traversal of its nodes' values. Example 1: Input: root = [1,null,2,3] Output: [3,2,1] Example 2: Input: root = [] Output: [] Example 3: Input: root = [1] Output: [1] Example 4: Input: root = [1,2] Output: [2,1] Example 5: Input: root = [1,null,2] Output: [2,1] Constraints: The number of the nodes in the tr..

144. Binary Tree Preorder Traversal Easy 252693Add to ListShare Given the root of a binary tree, return the preorder traversal of its nodes' values. Example 1: Input: root = [1,null,2,3] Output: [1,2,3] Example 2: Input: root = [] Output: [] Example 3: Input: root = [1] Output: [1] Example 4: Input: root = [1,2] Output: [1,2] Example 5: Input: root = [1,null,2] Output: [1,2] Constraints: The num..

110. Balanced Binary Tree Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as: a binary tree in which the left and right subtrees of every node differ in height by no more than 1. Example 1: Input: root = [3,9,20,null,null,15,7] Output: true Example 2: Input: root = [1,2,2,3,3,null,null,4,4] Output: false Example 3: Input: root =..

104. Maximum Depth of Binary Tree Easy 4338102Add to ListShare Given the root of a binary tree, return its maximum depth. A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. Example 1: Input: root = [3,9,20,null,null,15,7] Output: 3 Example 2: Input: root = [1,null,2] Output: 2 Example 3: Input: root = [] Output: 0 Exampl..

101. Symmetric Tree Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center). Example 1: Input: root = [1,2,2,3,4,4,3] Output: true Example 2: Input: root = [1,2,2,null,3,null,3] Output: false Constraints: The number of nodes in the tree is in the range [1, 1000]. -100 오른쪽 자식 노드 순서로 순회한다. preorderRight() 함수는 루트의 오른쪽 자식 노드가 루트가 되고, 현재 노드 -> 오른쪽 자..