Skip to content

Commit b56134f

Browse files
committed
이진 트리의 중위 순위 / 기초
1 parent 76a0e0e commit b56134f

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function inorderTraversal(root) {
2+
const result = [];
3+
4+
function inorder(node) {
5+
if (!node) return;
6+
7+
inorder(node.left);
8+
result.push(node.val);
9+
inorder(node.right);
10+
}
11+
12+
inorder(root);
13+
return result;
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* function TreeNode(val, left, right) {
4+
* this.val = (val===undefined ? 0 : val)
5+
* this.left = (left===undefined ? null : left)
6+
* this.right = (right===undefined ? null : right)
7+
* }
8+
*/
9+
/**
10+
* @param {TreeNode} root
11+
* @return {number}
12+
*/
13+
function maxDepth(root) {
14+
if (!root) return 0;
15+
16+
return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
17+
}

0 commit comments

Comments
 (0)