Skip to content

Commit 18e4f39

Browse files
committed
week15: add three js solution
1 parent 23d9602 commit 18e4f39

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@
273273
|171|[Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number/) | [Java](./algorithms/excelSheetColumnNumber/Solution.java) |Easy|
274274
|170|[Two Sum III - Data structure design](https://leetcode.com/problems/two-sum-iii-data-structure-design/) ♥ | |Easy|
275275
|169|[Majority Element](https://leetcode.com/problems/majority-element/) | [java](./algorithms/majorElement/Solution.java) |Easy|
276-
|168|[Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title/) | [Java](./algorithms/excelSheetColumnTitle/Solution.java) |Easy|
276+
|168|[Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title/) | [Java](./algorithms/excelSheetColumnTitle/Solution.java), [js](./algorithms/excelSheetColumnTitle/Solution.js) |Easy|
277277
|167|[Two Sum II - Input array is sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/) ♥ | |Medium|
278278
|166|[Fraction to Recurring Decimal](https://leetcode.com/problems/fraction-to-recurring-decimal/) | |Medium|
279279
|165|[Compare Version Numbers](https://leetcode.com/problems/compare-version-numbers/) | |Easy|
@@ -331,7 +331,7 @@
331331
|113|[Path Sum II](https://leetcode.com/problems/path-sum-ii/)| |Medium|
332332
|112|[Path Sum](https://leetcode.com/problems/path-sum/)| [js](./algorithms/pathSum/pathSum.js) |Easy|
333333
|111|[Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree/)| [js](./algorithms/minimumDepthOfBinaryTree/minimumDepthOfBinaryTree.js) |Easy|
334-
|110|[Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree/)| [java](./algorithms/balancedBinaryTree/Solution.java) |Easy|
334+
|110|[Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree/)| [java](./algorithms/balancedBinaryTree/Solution.java), [js](./algorithms/balancedBinaryTree/Solution.js) |Easy|
335335
|109|[Convert Sorted List to Binary Search Tree](https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/)| |Medium|
336336
|108|[Convert Sorted Array to Binary Search Tree](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/)| [Java](./algorithms/convertSortedArrayToBST/Solution.java) |Medium|
337337
|107|[Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii/)| |Easy|
@@ -353,7 +353,7 @@
353353
|91|[Decode Ways](https://leetcode.com/problems/decode-ways/)| |Medium|
354354
|90|[Subsets II](https://leetcode.com/problems/subsets-ii/)| |Medium|
355355
|89|[Gray Code](https://leetcode.com/problems/gray-code/)| |Medium|
356-
|88|[Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array/)| [java](./algorithms/mergeSortedArray/Solution.java) |Easy|
356+
|88|[Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array/)| [java](./algorithms/mergeSortedArray/Solution.java), [js](./algorithms/mergeSortedArray/Solution.js) |Easy|
357357
|87|[Scramble String](https://leetcode.com/problems/scramble-string/)| |Hard|
358358
|86|[Partition List](https://leetcode.com/problems/partition-list/)| |Medium|
359359
|85|[Maximal Rectangle](https://leetcode.com/problems/maximal-rectangle/)| |Hard|
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var isBalanced = function (root) {
2+
if(!root) return true
3+
return Math.abs(depth(root.left) - depth(root.right)) <= 1
4+
&& isBalanced(root.left)
5+
&& isBalanced(root.right)
6+
}
7+
var depth = function (node) {
8+
if(!node) return -1
9+
return 1 + Math.max(depth(node.left), depth(node.right))
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var convertToTitle = function(n) {
2+
const mod26 = (num) => {
3+
if (num <= 26) { return [num]; }
4+
if (num % 26 === 0) {
5+
return mod26((num / 26) -1).concat([26]);
6+
}
7+
return mod26(parseInt(num / 26)).concat([num % 26]);
8+
}
9+
return mod26(n).map(num => String.fromCharCode(num + 65 - 1)).join('');
10+
};
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var merge = function(nums1, m, nums2, n) {
2+
nums1.splice(m,n,...nums2);
3+
return nums1.sort((a,b) => a-b);
4+
};

0 commit comments

Comments
 (0)