Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1b18b54

Browse files
committedNov 6, 2020
add js solution for leetcode 104, 1137 and 面试题 08.06
1 parent 402f1a8 commit 1b18b54

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed
 

‎README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
|---| ----- | -------- | ---------- |
77
|1207|[Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences/) | |Easy|
88
|1170|[Compare Strings by Frequency of the Smallest Character](https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character/) | |Easy|
9+
|1137|[N-th Tribonacci Number](https://leetcode.com/problems/n-th-tribonacci-number/) | [js](./algorithms/nThTribonacciNumber/nThTribonacciNumber.js) |Easy|
910
|1071|[Greatest Common Divisor of Strings](https://leetcode.com/problems/greatest-common-divisor-of-strings/) | |Easy|
1011
|1030|[Matrix Cells in Distance Order](https://leetcode.com/problems/matrix-cells-in-distance-order/) | |Easy|
1112
|1029|[Two City Scheduling](https://leetcode.com/problems/two-city-scheduling/) | |Easy|
@@ -312,7 +313,7 @@
312313
|107|[Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii/)| |Easy|
313314
|106|[Construct Binary Tree from Inorder and Postorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/)| |Medium|
314315
|105|[Construct Binary Tree from Preorder and Inorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/)| |Medium|
315-
|104|[Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/)| |Easy|
316+
|104|[Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/)| [js](./algorithms/maximumDepthOfBinaryTree/maximumDepthOfBinaryTree.js) |Easy|
316317
|103|[Binary Tree Zigzag Level Order Traversal](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/)| |Medium|
317318
|102|[Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal/)| |Easy|
318319
|101|[Symmetric Tree](https://leetcode.com/problems/symmetric-tree/)| [java](./algorithms/sysmetricTree/Solution.java) |Easy|
@@ -416,3 +417,9 @@
416417
|3|[Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/)| [js](./algorithms/longestSubstringWithoutRepeatingCharacters/longestSubstringWithoutRepeatingCharacters.js) |Medium|
417418
|2|[Add Two Numbers](https://leetcode.com/problems/add-two-numbers/)| [js](./algorithms/addTwoNumbers/addTwoNumbers.js) |Medium|
418419
|1|[Two Sum](https://leetcode.com/problems/two-sum/) | [java](./algorithms/twoSum/twoSum.java), [js](./algorithms/twoSum/twoSum.js), [python](./algorithms/twoSum/twoSum.py) |Easy|
420+
421+
## 面试题
422+
423+
| # | Title | Solution | Difficulty |
424+
|---| ----- | -------- | ---------- |
425+
|面试题 08.06|[汉诺塔问题](https://leetcode-cn.com/problems/hanota-lcci/) | [js](./algorithms/hanotaLcc/hanotaLcc.js) |Easy|

‎algorithms/hanotaLcc/hanotaLcc.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var hanota = function(A, B, C) {
2+
const move = (n, from, buffer, to) => {
3+
if (n === 1) {
4+
console.log(A, '--->', C);
5+
to.push(from.pop());
6+
} else {
7+
move(n - 1, from, to, buffer);
8+
console.log(A, '--->', C);
9+
move(1, from, buffer, to);
10+
move(n - 1, buffer, from, to);
11+
}
12+
}
13+
move(A.length, A, B, C);
14+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var maxDepth = function(root) {
2+
if (!root) return 0;
3+
if (root.left === null && root.right === null) {
4+
return 1;
5+
}
6+
const leftDepth = maxDepth(root.left) + 1;
7+
const rightDepth = maxDepth(root.right) + 1;
8+
return Math.max(leftDepth, rightDepth);
9+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var tribonacci = function(n) {
2+
const map = [0, 1, 1];
3+
const recursion = (n) => {
4+
if (map[n] !== undefined) {
5+
return map[n];
6+
}
7+
map[n] = recursion(n - 1) + recursion(n - 2) + recursion(n - 3);
8+
return map[n];
9+
};
10+
return recursion(n);
11+
};

0 commit comments

Comments
 (0)
Please sign in to comment.