Skip to content

Commit fac00eb

Browse files
authored
Added tasks 99, 100, 103, 106.
1 parent cbe4cad commit fac00eb

File tree

14 files changed

+452
-0
lines changed

14 files changed

+452
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.4'
536536

537537
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
538538
|-|-|-|-|-|-
539+
| 0104 |[Maximum Depth of Binary Tree](src/main/kotlin/g0101_0200/s0104_maximum_depth_of_binary_tree/Solution.kt)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 236 | 83.39
539540

540541
#### Day 11 Containers and Libraries
541542

@@ -973,6 +974,7 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.4'
973974

974975
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
975976
|-|-|-|-|-|-
977+
| 0100 |[Same Tree](src/main/kotlin/g0001_0100/s0100_same_tree/Solution.kt)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 267 | 24.51
976978
| 0101 |[Symmetric Tree](src/main/kotlin/g0101_0200/s0101_symmetric_tree/Solution.kt)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 290 | 26.98
977979
| 0199 |[Binary Tree Right Side View](src/main/kotlin/g0101_0200/s0199_binary_tree_right_side_view/Solution.kt)| Medium | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 194 | 92.89
978980

@@ -1106,8 +1108,11 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.4'
11061108
|-|-|-|-|-|-
11071109
| 0094 |[Largest Rectangle in Histogram](src/main/kotlin/g0001_0100/s0094_binary_tree_inorder_traversal/Solution.kt)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Stack | 269 | 38.80
11081110
| 0102 |[Binary Tree Level Order Traversal](src/main/kotlin/g0101_0200/s0102_binary_tree_level_order_traversal/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree | 355 | 29.37
1111+
| 0103 |[Binary Tree Zigzag Level Order Traversal](src/main/kotlin/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/Solution.kt)| Medium | Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree | 316 | 34.25
11091112
| 0543 |[Diameter of Binary Tree](src/main/kotlin/g0501_0600/s0543_diameter_of_binary_tree/Solution.kt)| Easy | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree | 307 | 43.93
1113+
| 0100 |[Same Tree](src/main/kotlin/g0001_0100/s0100_same_tree/Solution.kt)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 267 | 24.51
11101114
| 0226 |[Invert Binary Tree](src/main/kotlin/g0201_0300/s0226_invert_binary_tree/Solution.kt)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 233 | 54.90
1115+
| 0104 |[Maximum Depth of Binary Tree](src/main/kotlin/g0101_0200/s0104_maximum_depth_of_binary_tree/Solution.kt)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 236 | 83.39
11111116
| 0124 |[Binary Tree Maximum Path Sum](src/main/kotlin/g0101_0200/s0124_binary_tree_maximum_path_sum/Solution.kt)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Depth_First_Search, Tree, Binary_Tree | 331 | 74.42
11121117
| 0098 |[Validate Binary Search Tree](src/main/kotlin/g0001_0100/s0098_validate_binary_search_tree/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree | 330 | 41.38
11131118
| 0236 |[Lowest Common Ancestor of a Binary Tree](src/main/kotlin/g0201_0300/s0236_lowest_common_ancestor_of_a_binary_tree/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree | 386 | 45.21
@@ -1231,6 +1236,7 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.4'
12311236
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
12321237
|-|-|-|-|-|-
12331238
| 0102 |[Binary Tree Level Order Traversal](src/main/kotlin/g0101_0200/s0102_binary_tree_level_order_traversal/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree | 355 | 29.37
1239+
| 0104 |[Maximum Depth of Binary Tree](src/main/kotlin/g0101_0200/s0104_maximum_depth_of_binary_tree/Solution.kt)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 236 | 83.39
12341240
| 0101 |[Symmetric Tree](src/main/kotlin/g0101_0200/s0101_symmetric_tree/Solution.kt)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 290 | 26.98
12351241

12361242
#### Day 12 Tree
@@ -1348,6 +1354,7 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.4'
13481354
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
13491355
|-|-|-|-|-|-
13501356
| 0105 |[Construct Binary Tree from Preorder and Inorder Traversal](src/main/kotlin/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Tree, Binary_Tree, Divide_and_Conquer | 370 | 58.31
1357+
| 0103 |[Binary Tree Zigzag Level Order Traversal](src/main/kotlin/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/Solution.kt)| Medium | Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree | 316 | 34.25
13511358

13521359
#### Day 16 Tree
13531360

@@ -1527,9 +1534,14 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.4'
15271534
| 0124 |[Binary Tree Maximum Path Sum](src/main/kotlin/g0101_0200/s0124_binary_tree_maximum_path_sum/Solution.kt)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Depth_First_Search, Tree, Binary_Tree, Udemy_Tree_Stack_Queue | 331 | 74.42
15281535
| 0121 |[Best Time to Buy and Sell Stock](src/main/kotlin/g0101_0200/s0121_best_time_to_buy_and_sell_stock/Solution.kt)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Data_Structure_I_Day_3_Array, Dynamic_Programming_I_Day_7, Level_1_Day_5_Greedy, Udemy_Arrays | 609 | 94.06
15291536
| 0114 |[Flatten Binary Tree to Linked List](src/main/kotlin/g0101_0200/s0114_flatten_binary_tree_to_linked_list/Solution.kt)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Linked_List, Udemy_Linked_List | 191 | 93.10
1537+
| 0106 |[Construct Binary Tree from Inorder and Postorder Traversal](src/main/kotlin/g0101_0200/s0106_construct_binary_tree_from_inorder_and_postorder_traversal/Solution.kt)| Medium | Array, Hash_Table, Tree, Binary_Tree, Divide_and_Conquer | 358 | 61.29
15301538
| 0105 |[Construct Binary Tree from Preorder and Inorder Traversal](src/main/kotlin/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Tree, Binary_Tree, Divide_and_Conquer, Data_Structure_II_Day_15_Tree | 370 | 58.31
1539+
| 0104 |[Maximum Depth of Binary Tree](src/main/kotlin/g0101_0200/s0104_maximum_depth_of_binary_tree/Solution.kt)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Data_Structure_I_Day_11_Tree, Programming_Skills_I_Day_10_Linked_List_and_Tree, Udemy_Tree_Stack_Queue | 236 | 83.39
1540+
| 0103 |[Binary Tree Zigzag Level Order Traversal](src/main/kotlin/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/Solution.kt)| Medium | Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Data_Structure_II_Day_15_Tree, Udemy_Tree_Stack_Queue | 316 | 34.25
15311541
| 0102 |[Binary Tree Level Order Traversal](src/main/kotlin/g0101_0200/s0102_binary_tree_level_order_traversal/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Data_Structure_I_Day_11_Tree, Level_1_Day_6_Tree, Udemy_Tree_Stack_Queue | 355 | 29.37
15321542
| 0101 |[Symmetric Tree](src/main/kotlin/g0101_0200/s0101_symmetric_tree/Solution.kt)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Data_Structure_I_Day_11_Tree, Level_2_Day_15_Tree | 290 | 26.98
1543+
| 0100 |[Same Tree](src/main/kotlin/g0001_0100/s0100_same_tree/Solution.kt)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Level_2_Day_15_Tree, Udemy_Tree_Stack_Queue | 267 | 24.51
1544+
| 0099 |[Recover Binary Search Tree](src/main/kotlin/g0001_0100/s0099_recover_binary_search_tree/Solution.kt)| Medium | Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree | 492 | 39.39
15331545
| 0098 |[Validate Binary Search Tree](src/main/kotlin/g0001_0100/s0098_validate_binary_search_tree/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Data_Structure_I_Day_14_Tree, Level_1_Day_8_Binary_Search_Tree, Udemy_Tree_Stack_Queue | 330 | 41.38
15341546
| 0097 |[Interleaving String](src/main/kotlin/g0001_0100/s0097_interleaving_string/Solution.kt)| Medium | String, Dynamic_Programming | 240 | 57.50
15351547
| 0096 |[Unique Binary Search Trees](src/main/kotlin/g0001_0100/s0096_unique_binary_search_trees/Solution.kt)| Medium | Top_100_Liked_Questions, Dynamic_Programming, Math, Tree, Binary_Tree, Binary_Search_Tree, Dynamic_Programming_I_Day_11 | 237 | 26.76
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package g0001_0100.s0099_recover_binary_search_tree
2+
3+
// #Medium #Depth_First_Search #Tree #Binary_Tree #Binary_Search_Tree
4+
// #2022_09_27_Time_492_ms_(39.39%)_Space_50.6_MB_(21.21%)
5+
6+
import com_github_leetcode.TreeNode
7+
8+
/*
9+
* Example:
10+
* var ti = TreeNode(5)
11+
* var v = ti.`val`
12+
* Definition for a binary tree node.
13+
* class TreeNode(var `val`: Int) {
14+
* var left: TreeNode? = null
15+
* var right: TreeNode? = null
16+
* }
17+
*/
18+
class Solution {
19+
private var prev: TreeNode? = null
20+
private var first: TreeNode? = null
21+
private var second: TreeNode? = null
22+
23+
fun recoverTree(root: TreeNode?) {
24+
evalSwappedNodes(root)
25+
val temp: Int = first!!.`val`
26+
first!!.`val` = second!!.`val`
27+
second!!.`val` = temp
28+
}
29+
30+
private fun evalSwappedNodes(curr: TreeNode?) {
31+
if (curr == null) {
32+
return
33+
}
34+
evalSwappedNodes(curr.left)
35+
if (prev != null && prev!!.`val` > curr.`val`) {
36+
if (first == null) {
37+
first = prev
38+
}
39+
second = curr
40+
}
41+
prev = curr
42+
evalSwappedNodes(curr.right)
43+
}
44+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
99\. Recover Binary Search Tree
2+
3+
Medium
4+
5+
You are given the `root` of a binary search tree (BST), where the values of **exactly** two nodes of the tree were swapped by mistake. _Recover the tree without changing its structure_.
6+
7+
**Example 1:**
8+
9+
![](https://assets.leetcode.com/uploads/2020/10/28/recover1.jpg)
10+
11+
**Input:** root = [1,3,null,null,2]
12+
13+
**Output:** [3,1,null,null,2]
14+
15+
**Explanation:** 3 cannot be a left child of 1 because 3 > 1. Swapping 1 and 3 makes the BST valid.
16+
17+
**Example 2:**
18+
19+
![](https://assets.leetcode.com/uploads/2020/10/28/recover2.jpg)
20+
21+
**Input:** root = [3,1,4,null,null,2]
22+
23+
**Output:** [2,1,4,null,null,3]
24+
25+
**Explanation:** 2 cannot be in the right subtree of 3 because 2 < 3. Swapping 2 and 3 makes the BST valid.
26+
27+
**Constraints:**
28+
29+
* The number of nodes in the tree is in the range `[2, 1000]`.
30+
* <code>-2<sup>31</sup> <= Node.val <= 2<sup>31</sup> - 1</code>
31+
32+
**Follow up:** A solution using `O(n)` space is pretty straight-forward. Could you devise a constant `O(1)` space solution?
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package g0001_0100.s0100_same_tree
2+
3+
// #Easy #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree #Level_2_Day_15_Tree
4+
// #Udemy_Tree_Stack_Queue #2022_09_27_Time_267_ms_(24.51%)_Space_34.1_MB_(43.10%)
5+
6+
import com_github_leetcode.TreeNode
7+
8+
/*
9+
* Example:
10+
* var ti = TreeNode(5)
11+
* var v = ti.`val`
12+
* Definition for a binary tree node.
13+
* class TreeNode(var `val`: Int) {
14+
* var left: TreeNode? = null
15+
* var right: TreeNode? = null
16+
* }
17+
*/
18+
class Solution {
19+
private fun trav(n: TreeNode?, m: TreeNode?): Boolean {
20+
return if (n != null && m != null) {
21+
if (n.`val` !== m.`val`) {
22+
false
23+
} else trav(n.left, m.left) && trav(n.right, m.right)
24+
} else {
25+
n == null && m == null
26+
}
27+
}
28+
29+
fun isSameTree(p: TreeNode?, q: TreeNode?): Boolean {
30+
if (p == null && q == null) {
31+
return true
32+
} else if (p == null || q == null) {
33+
return false
34+
}
35+
return trav(p, q)
36+
}
37+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
100\. Same Tree
2+
3+
Easy
4+
5+
Given the roots of two binary trees `p` and `q`, write a function to check if they are the same or not.
6+
7+
Two binary trees are considered the same if they are structurally identical, and the nodes have the same value.
8+
9+
**Example 1:**
10+
11+
![](https://assets.leetcode.com/uploads/2020/12/20/ex1.jpg)
12+
13+
**Input:** p = [1,2,3], q = [1,2,3]
14+
15+
**Output:** true
16+
17+
**Example 2:**
18+
19+
![](https://assets.leetcode.com/uploads/2020/12/20/ex2.jpg)
20+
21+
**Input:** p = [1,2], q = [1,null,2]
22+
23+
**Output:** false
24+
25+
**Example 3:**
26+
27+
![](https://assets.leetcode.com/uploads/2020/12/20/ex3.jpg)
28+
29+
**Input:** p = [1,2,1], q = [1,1,2]
30+
31+
**Output:** false
32+
33+
**Constraints:**
34+
35+
* The number of nodes in both trees is in the range `[0, 100]`.
36+
* <code>-10<sup>4</sup> <= Node.val <= 10<sup>4</sup></code>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package g0101_0200.s0103_binary_tree_zigzag_level_order_traversal
2+
3+
// #Medium #Top_Interview_Questions #Breadth_First_Search #Tree #Binary_Tree
4+
// #Data_Structure_II_Day_15_Tree #Udemy_Tree_Stack_Queue
5+
// #2022_09_27_Time_316_ms_(34.25%)_Space_35.3_MB_(95.21%)
6+
7+
import com_github_leetcode.TreeNode
8+
import java.util.LinkedList
9+
import java.util.Queue
10+
11+
/*
12+
* Example:
13+
* var ti = TreeNode(5)
14+
* var v = ti.`val`
15+
* Definition for a binary tree node.
16+
* class TreeNode(var `val`: Int) {
17+
* var left: TreeNode? = null
18+
* var right: TreeNode? = null
19+
* }
20+
*/
21+
class Solution {
22+
fun zigzagLevelOrder(root: TreeNode?): List<List<Int>> {
23+
val result: MutableList<List<Int>> = ArrayList()
24+
if (root == null) {
25+
return result
26+
}
27+
val q: Queue<TreeNode> = LinkedList()
28+
q.add(root)
29+
q.add(null)
30+
var zig = true
31+
var level = LinkedList<Int>()
32+
while (!q.isEmpty()) {
33+
var node: TreeNode? = q.remove()
34+
while (!q.isEmpty() && node != null) {
35+
if (zig) {
36+
level.add(node.`val`)
37+
} else {
38+
level.addFirst(node.`val`)
39+
}
40+
if (node.left != null) {
41+
q.add(node.left)
42+
}
43+
if (node.right != null) {
44+
q.add(node.right)
45+
}
46+
node = q.remove()
47+
}
48+
result.add(level)
49+
zig = !zig
50+
level = LinkedList()
51+
if (!q.isEmpty()) {
52+
q.add(null)
53+
}
54+
}
55+
return result
56+
}
57+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
103\. Binary Tree Zigzag Level Order Traversal
2+
3+
Medium
4+
5+
Given the `root` of a binary tree, return _the zigzag level order traversal of its nodes' values_. (i.e., from left to right, then right to left for the next level and alternate between).
6+
7+
**Example 1:**
8+
9+
![](https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg)
10+
11+
**Input:** root = [3,9,20,null,null,15,7]
12+
13+
**Output:** [[3],[20,9],[15,7]]
14+
15+
**Example 2:**
16+
17+
**Input:** root = [1]
18+
19+
**Output:** [[1]]
20+
21+
**Example 3:**
22+
23+
**Input:** root = []
24+
25+
**Output:** []
26+
27+
**Constraints:**
28+
29+
* The number of nodes in the tree is in the range `[0, 2000]`.
30+
* `-100 <= Node.val <= 100`
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
104\. Maximum Depth of Binary Tree
2+
3+
Easy
4+
5+
Given the `root` of a binary tree, return _its maximum depth_.
6+
7+
A binary tree's **maximum depth** is the number of nodes along the longest path from the root node down to the farthest leaf node.
8+
9+
**Example 1:**
10+
11+
![](https://assets.leetcode.com/uploads/2020/11/26/tmp-tree.jpg)
12+
13+
**Input:** root = [3,9,20,null,null,15,7]
14+
15+
**Output:** 3
16+
17+
**Example 2:**
18+
19+
**Input:** root = [1,null,2]
20+
21+
**Output:** 2
22+
23+
**Constraints:**
24+
25+
* The number of nodes in the tree is in the range <code>[0, 10<sup>4</sup>]</code>.
26+
* `-100 <= Node.val <= 100`
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package g0101_0200.s0106_construct_binary_tree_from_inorder_and_postorder_traversal
2+
3+
// #Medium #Array #Hash_Table #Tree #Binary_Tree #Divide_and_Conquer
4+
// #2022_09_27_Time_358_ms_(61.29%)_Space_37.1_MB_(96.77%)
5+
6+
import com_github_leetcode.TreeNode
7+
8+
/**
9+
* Example:
10+
* var ti = TreeNode(5)
11+
* var v = ti.`val`
12+
* Definition for a binary tree node.
13+
* class TreeNode(var `val`: Int) {
14+
* var left: TreeNode? = null
15+
* var right: TreeNode? = null
16+
* }
17+
*/
18+
class Solution {
19+
fun buildTree(inorder: IntArray, postorder: IntArray): TreeNode? {
20+
val inIndex = intArrayOf(inorder.size - 1)
21+
val postIndex = intArrayOf(postorder.size - 1)
22+
return helper(inorder, postorder, inIndex, postIndex, Int.MAX_VALUE)
23+
}
24+
25+
private fun helper(`in`: IntArray, post: IntArray, index: IntArray, pIndex: IntArray, target: Int): TreeNode? {
26+
if (index[0] < 0 || `in`[index[0]] == target) {
27+
return null
28+
}
29+
val root = TreeNode(post[pIndex[0]--])
30+
root.right = helper(`in`, post, index, pIndex, root.`val`)
31+
index[0]--
32+
root.left = helper(`in`, post, index, pIndex, target)
33+
return root
34+
}
35+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
106\. Construct Binary Tree from Inorder and Postorder Traversal
2+
3+
Medium
4+
5+
Given two integer arrays `inorder` and `postorder` where `inorder` is the inorder traversal of a binary tree and `postorder` is the postorder traversal of the same tree, construct and return _the binary tree_.
6+
7+
**Example 1:**
8+
9+
![](https://assets.leetcode.com/uploads/2021/02/19/tree.jpg)
10+
11+
**Input:** inorder = [9,3,15,20,7], postorder = [9,15,7,20,3]
12+
13+
**Output:** [3,9,20,null,null,15,7]
14+
15+
**Example 2:**
16+
17+
**Input:** inorder = [-1], postorder = [-1]
18+
19+
**Output:** [-1]
20+
21+
**Constraints:**
22+
23+
* `1 <= inorder.length <= 3000`
24+
* `postorder.length == inorder.length`
25+
* `-3000 <= inorder[i], postorder[i] <= 3000`
26+
* `inorder` and `postorder` consist of **unique** values.
27+
* Each value of `postorder` also appears in `inorder`.
28+
* `inorder` is **guaranteed** to be the inorder traversal of the tree.
29+
* `postorder` is **guaranteed** to be the postorder traversal of the tree.

0 commit comments

Comments
 (0)