Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8df3723

Browse files
update: 108
1 parent 2d36391 commit 8df3723

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ This is the solutions collection of my LeetCode submissions, most of them are pr
5858
|102|[Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal/) | [JavaScript](./src/binary-tree-level-order-traversal/res.js)|Medium|
5959
|104|[Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/) | [JavaScript](./src/maximum-depth-of-binary-tree/res.js)|Easy|
6060
|107|[Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii/) | [JavaScript](./src/binary-tree-level-order-traversal-ii/res.js)|Easy|
61+
|108|[Convert Sorted Array to Binary Search Tree](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/) | [JavaScript](./src/convert-sorted-array-to-binary-search-tree/res.js)|Easy|
6162
|111|[Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree/) | [JavaScript](./src/minimum-depth-of-binary-tree/res.js)|Easy|
6263
|120|[Triangle](https://leetcode.com/problems/triangle/) | [JavaScript](./src/triangle/res.js)|Medium|
6364
|121|[Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/) | [JavaScript](./src/best-time-to-buy-and-sell-stock/res.js)|Easy|
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* function TreeNode(val) {
4+
* this.val = val;
5+
* this.left = this.right = null;
6+
* }
7+
*/
8+
/**
9+
* @param {number[]} nums
10+
* @return {TreeNode}
11+
*/
12+
var sortedArrayToBST = function(nums) {
13+
const len = nums.length;
14+
if (!len) return null;
15+
16+
const treeNode = (left, right) => {
17+
if (left > right) return null;
18+
const mid = (left + right) >> 1;
19+
20+
const node = {
21+
val: nums[mid]
22+
};
23+
24+
node.left = treeNode(left, mid - 1);
25+
node.right = treeNode(mid+1, right);
26+
27+
return node;
28+
}
29+
30+
return treeNode(0, len-1);
31+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /