Skip to content

Commit 9401148

Browse files
committed
[leet] binary search tree + bk
1 parent 9c6499a commit 9401148

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @param {string} digits
3+
* @return {string[]}
4+
*/
5+
var letterCombinations = function(digits) {
6+
const obj ={
7+
2: ['a','b','c'],
8+
3: ['d','e','f'],
9+
4: ['g','h','i'],
10+
5: ['j','k','l'],
11+
6: ['m','n','o'],
12+
7: ['p','q','r','s'],
13+
8: ['t','u','v'],
14+
9: ['w','x','y','z']
15+
}
16+
17+
const ans = [];
18+
const bkArr = []
19+
const bk = (digitCount) =>{
20+
if(digitCount === digits.length){
21+
ans.push(bkArr.join(""))
22+
return
23+
}
24+
for(let i = 0 ; i< obj[digits[digitCount]].length;i++) {
25+
bkArr[digitCount] = obj[digits[digitCount]][i]
26+
bk(digitCount+1)
27+
}
28+
}
29+
for(let i = 0 ; i< obj[digits[0]].length; i++ ){
30+
bkArr[0] = obj[digits[0]][i]
31+
bk(1)
32+
33+
}
34+
return ans
35+
};
36+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 {TreeNode}
12+
*/
13+
var invertTree = function(root) {
14+
const swapChildren = (node) => {
15+
const temp = node.left;
16+
node.left = node.right;
17+
node.right = temp;
18+
};
19+
20+
const traverseTree = (node) => {
21+
if (!node) return;
22+
23+
swapChildren(node);
24+
traverseTree(node.left);
25+
traverseTree(node.right);
26+
};
27+
28+
traverseTree(root);
29+
return root;
30+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* @param {TreeNode} root
3+
* @return {number}
4+
*/
5+
var maxDepth = function(root) {
6+
const findDepth = (node, count) =>{
7+
if(!node) return count
8+
return Math.max(findDepth(node.left, count+1), findDepth(node.right, count+1))
9+
}
10+
return findDepth(root, 0)
11+
};

허현빈/10주차/Symmetric Tree.js

Whitespace-only changes.

0 commit comments

Comments
 (0)