Skip to content

Commit 015906a

Browse files
committed
add js problems
1 parent e6c0106 commit 015906a

File tree

169 files changed

+7451
-5812
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

169 files changed

+7451
-5812
lines changed

assets/output/0098.md

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,87 +9,65 @@ tree (BST)_.
99

1010
A **valid BST** is defined as follows:
1111

12-
* The left subtree of a node contains only nodes with keys **less than** the node's key.
13-
* The right subtree of a node contains only nodes with keys **greater than** the node's key.
14-
* Both the left and right subtrees must also be binary search trees.
15-
16-
12+
- The left subtree of a node contains only nodes with keys **less than** the node's key.
13+
- The right subtree of a node contains only nodes with keys **greater than** the node's key.
14+
- Both the left and right subtrees must also be binary search trees.
1715

1816
**Example 1:**
1917

2018
![](https://assets.leetcode.com/uploads/2020/12/01/tree1.jpg)
2119

2220
> Input: root = [2,1,3]
23-
>
21+
>
2422
> Output: true
2523
2624
**Example 2:**
2725

2826
![](https://assets.leetcode.com/uploads/2020/12/01/tree2.jpg)
2927

3028
> Input: root = [5,1,4,null,null,3,6]
31-
>
29+
>
3230
> Output: false
33-
>
31+
>
3432
> Explanation: The root node's value is 5 but its right child's value is 4.
3533
3634
**Constraints:**
3735

38-
* The number of nodes in the tree is in the range `[1, 104]`.
39-
* `-231 <= Node.val <= 231 - 1`
40-
36+
- The number of nodes in the tree is in the range `[1, 10^4]`.
37+
- `-231 <= Node.val <= 231 - 1`
4138

4239
## 题目大意
4340

4441
给你一个二叉树的根节点 `root` ,判断其是否是一个有效的二叉搜索树。
4542

4643
**有效** 二叉搜索树定义如下:
4744

48-
* 节点的左子树只包含**小于** 当前节点的数。
49-
* 节点的右子树只包含 **大于** 当前节点的数。
50-
* 所有左子树和右子树自身必须也是二叉搜索树。
51-
52-
45+
- 节点的左子树只包含**小于** 当前节点的数。
46+
- 节点的右子树只包含 **大于** 当前节点的数。
47+
- 所有左子树和右子树自身必须也是二叉搜索树。
5348

5449
**示例 1:**
5550

5651
![](https://assets.leetcode.com/uploads/2020/12/01/tree1.jpg)
5752

58-
>
59-
>
60-
>
61-
>
62-
>
6353
> **输入:** root = [2,1,3]
64-
>
54+
>
6555
> **输出:** true
66-
>
67-
>
6856
6957
**示例 2:**
7058

7159
![](https://assets.leetcode.com/uploads/2020/12/01/tree2.jpg)
7260

73-
>
74-
>
75-
>
76-
>
77-
>
7861
> **输入:** root = [5,1,4,null,null,3,6]
79-
>
62+
>
8063
> **输出:** false
81-
>
64+
>
8265
> **解释:** 根节点的值是 5 ,但是右子节点的值是 4 。
83-
>
84-
>
85-
86-
8766
8867
**提示:**
8968

90-
* 树中节点数目范围在`[1, 104]`
91-
* `-231 <= Node.val <= 231 - 1`
92-
69+
- 树中节点数目范围在`[1, 10^4]`
70+
- `-231 <= Node.val <= 231 - 1`
9371

9472
## 解题思路
9573

assets/output/0104.md

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,76 +6,52 @@
66

77
Given the `root` of a binary tree, return _its maximum depth_.
88

9-
A binary tree's **maximum depth** is the number of nodes along the longest
9+
A binary tree's **maximum depth** is the number of nodes along the longest
1010
path from the root node down to the farthest leaf node.
1111

12-
13-
1412
**Example 1:**
1513

1614
![](https://assets.leetcode.com/uploads/2020/11/26/tmp-tree.jpg)
1715

1816
> Input: root = [3,9,20,null,null,15,7]
19-
>
17+
>
2018
> Output: 3
2119
2220
**Example 2:**
2321

2422
> Input: root = [1,null,2]
25-
>
23+
>
2624
> Output: 2
2725
2826
**Constraints:**
2927

30-
* The number of nodes in the tree is in the range `[0, 104]`.
31-
* `-100 <= Node.val <= 100`
32-
28+
- The number of nodes in the tree is in the range `[0, 10^4]`.
29+
- `-100 <= Node.val <= 100`
3330

3431
## 题目大意
3532

3633
给定一个二叉树 `root` ,返回其最大深度。
3734

3835
二叉树的 **最大深度** 是指从根节点到最远叶子节点的最长路径上的节点数。
3936

40-
41-
4237
**示例 1:**
4338

4439
![](https://assets.leetcode.com/uploads/2020/11/26/tmp-tree.jpg)
4540

46-
47-
48-
>
49-
>
50-
>
51-
>
52-
>
5341
> **输入:** root = [3,9,20,null,null,15,7]
54-
>
42+
>
5543
> **输出:** 3
56-
>
57-
>
5844
5945
**示例 2:**
6046

61-
>
62-
>
63-
>
64-
>
65-
>
6647
> **输入:** root = [1,null,2]
67-
>
48+
>
6849
> **输出:** 2
69-
>
70-
>
71-
72-
7350
7451
**提示:**
7552

76-
* 树中节点的数量在 `[0, 104]` 区间内。
77-
* `-100 <= Node.val <= 100`
78-
53+
- 树中节点的数量在 `[0, 10^4]` 区间内。
54+
- `-100 <= Node.val <= 100`
7955

8056
## 解题思路
8157

assets/output/0109.md

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,73 +8,51 @@ Given the `head` of a singly linked list where elements are sorted in
88
**ascending order** , convert _it to a_** _height-balanced_** _binary search
99
tree_.
1010

11-
12-
1311
**Example 1:**
1412

1513
![](https://assets.leetcode.com/uploads/2020/08/17/linked.jpg)
1614

1715
> Input: head = [-10,-3,0,5,9]
18-
>
16+
>
1917
> Output: [0,-3,9,-10,null,5]
20-
>
18+
>
2119
> Explanation: One possible answer is [0,-3,9,-10,null,5], which represents the shown height balanced BST.
2220
2321
**Example 2:**
2422

2523
> Input: head = []
26-
>
24+
>
2725
> Output: []
2826
2927
**Constraints:**
3028

31-
* The number of nodes in `head` is in the range `[0, 2 * 104]`.
32-
* `-10^5 <= Node.val <= 10^5`
33-
29+
- The number of nodes in `head` is in the range `[0, 2 * 10^4]`.
30+
- `-10^5 <= Node.val <= 10^5`
3431

3532
## 题目大意
3633

37-
给定一个单链表的头节点 `head` ,其中的元素 **按升序排序** ,将其转换为 平衡 二叉搜索树。
38-
39-
34+
给定一个单链表的头节点 `head` ,其中的元素 **按升序排序** ,将其转换为 平衡 二叉搜索树。
4035

4136
**示例 1:**
4237

4338
![](https://assets.leetcode.com/uploads/2020/08/17/linked.jpg)
4439

45-
>
46-
>
47-
>
48-
>
49-
>
5040
> **输入:** head = [-10,-3,0,5,9]
51-
>
41+
>
5242
> **输出:** [0,-3,9,-10,null,5]
53-
>
43+
>
5444
> **解释:** 一个可能的答案是[0,-3,9,-10,null,5],它表示所示的高度平衡的二叉搜索树。
55-
>
56-
>
5745
5846
**示例 2:**
5947

60-
>
61-
>
62-
>
63-
>
64-
>
6548
> **输入:** head = []
66-
>
49+
>
6750
> **输出:** []
68-
>
69-
>
70-
71-
7251
7352
**提示:**
7453

75-
* `head` 中的节点数在`[0, 2 * 104]` 范围内
76-
* `-10^5 <= Node.val <= 10^5`
77-
54+
- `head` 中的节点数在`[0, 2 * 10^4]` 范围内
55+
- `-10^5 <= Node.val <= 10^5`
7856

7957
## 解题思路
8058

assets/output/0111.md

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,26 @@ Given a binary tree, find its minimum depth.
99
The minimum depth is the number of nodes along the shortest path from the root
1010
node down to the nearest leaf node.
1111

12-
**Note:** A leaf is a node with no children.
13-
14-
12+
**Note:** A leaf is a node with no children.
1513

1614
**Example 1:**
1715

1816
![](https://assets.leetcode.com/uploads/2020/10/12/ex_depth.jpg)
1917

2018
> Input: root = [3,9,20,null,null,15,7]
21-
>
19+
>
2220
> Output: 2
2321
2422
**Example 2:**
2523

2624
> Input: root = [2,null,3,null,4,null,5,null,6]
27-
>
25+
>
2826
> Output: 5
2927
3028
**Constraints:**
3129

32-
* The number of nodes in the tree is in the range `[0, 105]`.
33-
* `-1000 <= Node.val <= 1000`
34-
30+
- The number of nodes in the tree is in the range `[0, 10^5]`.
31+
- `-1000 <= Node.val <= 1000`
3532

3633
## 题目大意
3734

@@ -45,35 +42,20 @@ node down to the nearest leaf node.
4542

4643
![](https://assets.leetcode.com/uploads/2020/10/12/ex_depth.jpg)
4744

48-
>
49-
>
50-
>
51-
>
52-
>
5345
> **输入:** root = [3,9,20,null,null,15,7]
54-
>
46+
>
5547
> **输出:** 2
56-
>
57-
>
5848
5949
**示例 2:**
6050

61-
>
62-
>
63-
>
64-
>
65-
>
6651
> **输入:** root = [2,null,3,null,4,null,5,null,6]
67-
>
52+
>
6853
> **输出:** 5
69-
>
70-
>
7154
7255
**提示:**
7356

74-
* 树中节点数的范围在 `[0, 105]`
75-
* `-1000 <= Node.val <= 1000`
76-
57+
- 树中节点数的范围在 `[0, 10^5]`
58+
- `-1000 <= Node.val <= 1000`
7759

7860
## 解题思路
7961

0 commit comments

Comments
 (0)