Skip to content

Commit 19a142d

Browse files
authored
[JustDevRae] 25.02.07 (#39)
* remove smallest number / 중급 * divisible numbers array / 중급 * duplicate number count / 기초 * matrix addition / 중급 * array element length / 기초 * rotate array / 기초 * slice array / 기초 * array algorithm md file * reverse string / 기초 * control Z / 기초 * dart game / 중급 * valid parentheses / 중급 * crane claw game / 중급 * pair count / 기초 * find point position / 기초 * login success / 기초 * card bundle / 중급 * make hamburger / 중급 * process / 심화 * morse code / 기초 * make B with A / 기초 * setting order care / 기초 * not finish runner / 중급 * rank order / 기초 * sameTree / 기초 * invert binary tree / 기초 * maximum depth of binary / 기초 * binary tree inorder traversal / 기초 * binary tree level order traversal / 중급
1 parent eb4df84 commit 19a142d

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function inorderTraversal(root) {
2+
let result = [];
3+
let stack = [];
4+
let current = root;
5+
6+
while (current || stack.length) {
7+
while (current) {
8+
stack.push(current);
9+
current = current.left;
10+
}
11+
12+
current = stack.pop();
13+
result.push(current.val);
14+
current = current.right;
15+
}
16+
17+
return result;
18+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function levelOrder(root) {
2+
if (!root) return [];
3+
4+
let result = [];
5+
let queue = [root];
6+
7+
while (queue.length > 0) {
8+
let level = [];
9+
let size = queue.length;
10+
11+
for (let i = 0; i < size; i++) {
12+
let node = queue.shift();
13+
level.push(node.val);
14+
15+
if (node.left) queue.push(node.left);
16+
if (node.right) queue.push(node.right);
17+
}
18+
19+
result.push(level);
20+
}
21+
22+
return result;
23+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function invertTree(root) {
2+
if (!root) return null;
3+
4+
[root.left, root.right] = [root.right, root.left];
5+
6+
invertTree(root.left);
7+
invertTree(root.right);
8+
9+
return root;
10+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function maxDepth(root) {
2+
if (!root) return 0;
3+
4+
return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
5+
}

JustDevRae/Tree/same_tree.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function isSameTree(p, q) {
2+
3+
if (!p && !q) return true;
4+
5+
if (!p || !q) return false;
6+
7+
if (p.val !== q.val) return false;
8+
9+
return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
10+
}

0 commit comments

Comments
 (0)