Skip to content

Commit baaf053

Browse files
authored
Added tasks 103-117
1 parent 3438187 commit baaf053

File tree

16 files changed

+486
-0
lines changed

16 files changed

+486
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ Python-based LeetCode algorithm problem solutions, regularly updated.
295295

296296
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
297297
|-|-|-|-|-|-
298+
| 0108 |[Convert Sorted Array to Binary Search Tree](src/main/python/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/Solution0108.py)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Tree, Binary_Tree, Binary_Search_Tree, Divide_and_Conquer | 0 | 100.00
298299
| 0230 |[Kth Smallest Element in a BST](src/main/python/g0201_0300/s0230_kth_smallest_element_in_a_bst/Solution0230.py)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
299300

300301
#### Day 10 Graph/BFS/DFS
@@ -464,6 +465,8 @@ Python-based LeetCode algorithm problem solutions, regularly updated.
464465
|-|-|-|-|-|-
465466
| 0094 |[Binary Tree Inorder Traversal](src/main/python/g0001_0100/s0094_binary_tree_inorder_traversal/Solution0094.py)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
466467
| 0102 |[Binary Tree Level Order Traversal](src/main/python/g0101_0200/s0102_binary_tree_level_order_traversal/Solution0102.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 0 | 100.00
468+
| 0103 |[Binary Tree Zigzag Level Order Traversal](src/main/python/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/Solution0103.py)| Medium | Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00
469+
| 0108 |[Convert Sorted Array to Binary Search Tree](src/main/python/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/Solution0108.py)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Tree, Binary_Tree, Binary_Search_Tree, Divide_and_Conquer | 0 | 100.00
467470
| 0543 |[Diameter of Binary Tree](src/main/python/g0501_0600/s0543_diameter_of_binary_tree/Solution0543.py)| Easy | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 3 | 94.30
468471
| 0100 |[Same Tree](src/main/python/g0001_0100/s0100_same_tree/Solution0100.py)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00
469472
| 0226 |[Invert Binary Tree](src/main/python/g0201_0300/s0226_invert_binary_tree/Solution0226.py)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
@@ -617,7 +620,10 @@ Python-based LeetCode algorithm problem solutions, regularly updated.
617620
| 0226 |[Invert Binary Tree](src/main/python/g0201_0300/s0226_invert_binary_tree/Solution0226.py)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
618621
| 0101 |[Symmetric Tree](src/main/python/g0101_0200/s0101_symmetric_tree/Solution0101.py)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 0 | 100.00
619622
| 0105 |[Construct Binary Tree from Preorder and Inorder Traversal](src/main/python/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/Solution0105.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Tree, Binary_Tree, Divide_and_Conquer, Big_O_Time_O(N)_Space_O(N) | 4 | 73.84
623+
| 0106 |[Construct Binary Tree from Inorder and Postorder Traversal](src/main/python/g0101_0200/s0106_construct_binary_tree_from_inorder_and_postorder_traversal/Solution0106.py)| Medium | Array, Hash_Table, Tree, Binary_Tree, Divide_and_Conquer | 0 | 100.00
624+
| 0117 |[Populating Next Right Pointers in Each Node II](src/main/python/g0101_0200/s0117_populating_next_right_pointers_in_each_node_ii/Solution0117.py)| Medium | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Linked_List | 44 | 70.94
620625
| 0114 |[Flatten Binary Tree to Linked List](src/main/python/g0101_0200/s0114_flatten_binary_tree_to_linked_list/Solution0114.py)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Linked_List, Big_O_Time_O(N)_Space_O(N) | 0 | 100.00
626+
| 0112 |[Path Sum](src/main/python/g0101_0200/s0112_path_sum/Solution0112.py)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00
621627
| 0124 |[Binary Tree Maximum Path Sum](src/main/python/g0101_0200/s0124_binary_tree_maximum_path_sum/Solution0124.py)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 11 | 91.40
622628
| 0236 |[Lowest Common Ancestor of a Binary Tree](src/main/python/g0201_0300/s0236_lowest_common_ancestor_of_a_binary_tree/Solution0236.py)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Big_O_Time_O(n)_Space_O(n) | 41 | 97.74
623629

@@ -626,6 +632,7 @@ Python-based LeetCode algorithm problem solutions, regularly updated.
626632
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
627633
|-|-|-|-|-|-
628634
| 0102 |[Binary Tree Level Order Traversal](src/main/python/g0101_0200/s0102_binary_tree_level_order_traversal/Solution0102.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 0 | 100.00
635+
| 0103 |[Binary Tree Zigzag Level Order Traversal](src/main/python/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/Solution0103.py)| Medium | Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00
629636

630637
#### Top Interview 150 Binary Search Tree
631638

@@ -667,6 +674,7 @@ Python-based LeetCode algorithm problem solutions, regularly updated.
667674

668675
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
669676
|-|-|-|-|-|-
677+
| 0108 |[Convert Sorted Array to Binary Search Tree](src/main/python/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/Solution0108.py)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Tree, Binary_Tree, Binary_Search_Tree, Divide_and_Conquer | 0 | 100.00
670678
| 0148 |[Sort List](src/main/python/g0101_0200/s0148_sort_list/Solution0148.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Sorting, Two_Pointers, Linked_List, Divide_and_Conquer, Merge_Sort, Big_O_Time_O(log(N))_Space_O(log(N)) | 186 | 43.67
671679
| 0023 |[Merge k Sorted Lists](src/main/python/g0001_0100/s0023_merge_k_sorted_lists/Solution0023.py)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Heap_Priority_Queue, Linked_List, Divide_and_Conquer, Merge_Sort, Big_O_Time_O(k\*n\*log(k))_Space_O(log(k)) | 5 | 93.52
672680

@@ -805,6 +813,7 @@ Python-based LeetCode algorithm problem solutions, regularly updated.
805813
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
806814
|-|-|-|-|-|-
807815
| 0226 |[Invert Binary Tree](src/main/python/g0201_0300/s0226_invert_binary_tree/Solution0226.py)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
816+
| 0112 |[Path Sum](src/main/python/g0101_0200/s0112_path_sum/Solution0112.py)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00
808817

809818
#### Day 13 Tree
810819

@@ -912,7 +921,9 @@ Python-based LeetCode algorithm problem solutions, regularly updated.
912921

913922
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
914923
|-|-|-|-|-|-
924+
| 0108 |[Convert Sorted Array to Binary Search Tree](src/main/python/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/Solution0108.py)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Tree, Binary_Tree, Binary_Search_Tree, Divide_and_Conquer | 0 | 100.00
915925
| 0105 |[Construct Binary Tree from Preorder and Inorder Traversal](src/main/python/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/Solution0105.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Tree, Binary_Tree, Divide_and_Conquer, Big_O_Time_O(N)_Space_O(N) | 4 | 73.84
926+
| 0103 |[Binary Tree Zigzag Level Order Traversal](src/main/python/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/Solution0103.py)| Medium | Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00
916927

917928
#### Day 16 Tree
918929

@@ -1077,6 +1088,7 @@ Python-based LeetCode algorithm problem solutions, regularly updated.
10771088

10781089
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
10791090
|-|-|-|-|-|-
1091+
| 0117 |[Populating Next Right Pointers in Each Node II](src/main/python/g0101_0200/s0117_populating_next_right_pointers_in_each_node_ii/Solution0117.py)| Medium | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Linked_List | 44 | 70.94
10801092

10811093
#### Day 8 Breadth First Search Depth First Search
10821094

@@ -1692,9 +1704,14 @@ Python-based LeetCode algorithm problem solutions, regularly updated.
16921704
| 0128 |[Longest Consecutive Sequence](src/main/python/g0101_0200/s0128_longest_consecutive_sequence/Solution0128.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Union_Find, Top_Interview_150_Hashmap, Big_O_Time_O(N_log_N)_Space_O(1) | 47 | 76.47
16931705
| 0124 |[Binary Tree Maximum Path Sum](src/main/python/g0101_0200/s0124_binary_tree_maximum_path_sum/Solution0124.py)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Depth_First_Search, Tree, Binary_Tree, Udemy_Tree_Stack_Queue, Top_Interview_150_Binary_Tree_General, Big_O_Time_O(N)_Space_O(N) | 11 | 91.40
16941706
| 0121 |[Best Time to Buy and Sell Stock](src/main/python/g0101_0200/s0121_best_time_to_buy_and_sell_stock/Solution0121.py)| 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, Top_Interview_150_Array/String, Big_O_Time_O(N)_Space_O(1) | 17 | 98.03
1707+
| 0117 |[Populating Next Right Pointers in Each Node II](src/main/python/g0101_0200/s0117_populating_next_right_pointers_in_each_node_ii/Solution0117.py)| Medium | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Linked_List, Algorithm_II_Day_7_Breadth_First_Search_Depth_First_Search, Top_Interview_150_Binary_Tree_General | 44 | 70.94
16951708
| 0114 |[Flatten Binary Tree to Linked List](src/main/python/g0101_0200/s0114_flatten_binary_tree_to_linked_list/Solution0114.py)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Linked_List, Udemy_Linked_List, Top_Interview_150_Binary_Tree_General, Big_O_Time_O(N)_Space_O(N) | 0 | 100.00
1709+
| 0112 |[Path Sum](src/main/python/g0101_0200/s0112_path_sum/Solution0112.py)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Data_Structure_I_Day_12_Tree, Top_Interview_150_Binary_Tree_General | 0 | 100.00
1710+
| 0108 |[Convert Sorted Array to Binary Search Tree](src/main/python/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/Solution0108.py)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Tree, Binary_Tree, Binary_Search_Tree, Divide_and_Conquer, Data_Structure_II_Day_15_Tree, Level_2_Day_9_Binary_Search_Tree, Udemy_Tree_Stack_Queue, Top_Interview_150_Divide_and_Conquer | 0 | 100.00
1711+
| 0106 |[Construct Binary Tree from Inorder and Postorder Traversal](src/main/python/g0101_0200/s0106_construct_binary_tree_from_inorder_and_postorder_traversal/Solution0106.py)| Medium | Array, Hash_Table, Tree, Binary_Tree, Divide_and_Conquer, Top_Interview_150_Binary_Tree_General | 0 | 100.00
16961712
| 0105 |[Construct Binary Tree from Preorder and Inorder Traversal](src/main/python/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/Solution0105.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Tree, Binary_Tree, Divide_and_Conquer, Data_Structure_II_Day_15_Tree, Top_Interview_150_Binary_Tree_General, Big_O_Time_O(N)_Space_O(N) | 4 | 73.84
16971713
| 0104 |[Maximum Depth of Binary Tree](src/main/python/g0101_0200/s0104_maximum_depth_of_binary_tree/Solution0104.py)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, LeetCode_75_Binary_Tree/DFS, Data_Structure_I_Day_11_Tree, Programming_Skills_I_Day_10_Linked_List_and_Tree, Udemy_Tree_Stack_Queue, Top_Interview_150_Binary_Tree_General, Big_O_Time_O(N)_Space_O(H) | 0 | 100.00
1714+
| 0103 |[Binary Tree Zigzag Level Order Traversal](src/main/python/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/Solution0103.py)| Medium | Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Data_Structure_II_Day_15_Tree, Udemy_Tree_Stack_Queue, Top_Interview_150_Binary_Tree_BFS | 0 | 100.00
16981715
| 0102 |[Binary Tree Level Order Traversal](src/main/python/g0101_0200/s0102_binary_tree_level_order_traversal/Solution0102.py)| 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, Top_Interview_150_Binary_Tree_BFS, Big_O_Time_O(N)_Space_O(N) | 0 | 100.00
16991716
| 0101 |[Symmetric Tree](src/main/python/g0101_0200/s0101_symmetric_tree/Solution0101.py)| 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, Top_Interview_150_Binary_Tree_General, Big_O_Time_O(N)_Space_O(log(N)) | 0 | 100.00
17001717
| 0100 |[Same Tree](src/main/python/g0001_0100/s0100_same_tree/Solution0100.py)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Level_2_Day_15_Tree, Udemy_Tree_Stack_Queue, Top_Interview_150_Binary_Tree_General | 0 | 100.00
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# #Medium #Top_Interview_Questions #Breadth_First_Search #Tree #Binary_Tree
2+
# #Data_Structure_II_Day_15_Tree #Udemy_Tree_Stack_Queue #Top_Interview_150_Binary_Tree_BFS
3+
# #2025_09_14_Time_0_ms_(100.00%)_Space_18.25_MB_(8.14%)
4+
5+
from typing import List, Optional
6+
from collections import deque
7+
8+
class TreeNode:
9+
def __init__(self, val=0, left=None, right=None):
10+
self.val = val
11+
self.left = left
12+
self.right = right
13+
14+
class Solution:
15+
def zigzagLevelOrder(self, root: Optional[TreeNode]) -> List[List[int]]:
16+
result = []
17+
if root is None:
18+
return result
19+
q = deque()
20+
q.append(root)
21+
q.append(None)
22+
zig = True
23+
level = deque()
24+
while q:
25+
node = q.popleft()
26+
while q and node is not None:
27+
if zig:
28+
level.append(node.val)
29+
else:
30+
level.appendleft(node.val)
31+
if node.left is not None:
32+
q.append(node.left)
33+
if node.right is not None:
34+
q.append(node.right)
35+
node = q.popleft()
36+
result.append(list(level))
37+
zig = not zig
38+
level = deque()
39+
if q:
40+
q.append(None)
41+
return result
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import unittest
2+
from Solution0103 import Solution, TreeNode
3+
4+
class SolutionTest(unittest.TestCase):
5+
def test_zigzagLevelOrder(self):
6+
root = TreeNode(3)
7+
root.left = TreeNode(9)
8+
root.right = TreeNode(20)
9+
root.right.left = TreeNode(15)
10+
root.right.right = TreeNode(7)
11+
actual = Solution().zigzagLevelOrder(root)
12+
expected = [[3], [20, 9], [15, 7]]
13+
self.assertEqual(actual, expected)
14+
15+
def test_zigzagLevelOrder2(self):
16+
root = TreeNode(1)
17+
actual = Solution().zigzagLevelOrder(root)
18+
expected = [[1]]
19+
self.assertEqual(actual, expected)
20+
21+
def test_zigzagLevelOrder3(self):
22+
actual = Solution().zigzagLevelOrder(None)
23+
expected = []
24+
self.assertEqual(actual, expected)
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+
# #Medium #Array #Hash_Table #Tree #Binary_Tree #Divide_and_Conquer
2+
# #Top_Interview_150_Binary_Tree_General #2025_09_14_Time_0_ms_(100.00%)_Space_19.02_MB_(96.74%)
3+
4+
from typing import List, Optional
5+
6+
class TreeNode:
7+
def __init__(self, val=0, left=None, right=None):
8+
self.val = val
9+
self.left = left
10+
self.right = right
11+
12+
class Solution:
13+
def buildTree(self, inorder: List[int], postorder: List[int]) -> Optional[TreeNode]:
14+
in_index = [len(inorder) - 1]
15+
post_index = [len(postorder) - 1]
16+
return self._helper(inorder, postorder, in_index, post_index, float('inf'))
17+
18+
def _helper(self, inorder: List[int], postorder: List[int], index: List[int], p_index: List[int], target: int) -> Optional[TreeNode]:
19+
if index[0] < 0 or (index[0] < len(inorder) and inorder[index[0]] == target):
20+
return None
21+
root = TreeNode(postorder[p_index[0]])
22+
p_index[0] -= 1
23+
root.right = self._helper(inorder, postorder, index, p_index, root.val)
24+
index[0] -= 1
25+
root.left = self._helper(inorder, postorder, index, p_index, target)
26+
return root
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import unittest
2+
from Solution0106 import Solution
3+
4+
class SolutionTest(unittest.TestCase):
5+
def test_buildTree(self):
6+
inorder = [9, 3, 15, 20, 7]
7+
postorder = [9, 15, 7, 20, 3]
8+
actual = Solution().buildTree(inorder, postorder)
9+
# Convert tree to string representation for comparison
10+
result = self._tree_to_string(actual)
11+
self.assertEqual(result, "9,3,15,20,7")
12+
13+
def test_buildTree2(self):
14+
inorder = [-1]
15+
postorder = [-1]
16+
actual = Solution().buildTree(inorder, postorder)
17+
result = self._tree_to_string(actual)
18+
self.assertEqual(result, "-1")
19+
20+
def _tree_to_string(self, root):
21+
if root is None:
22+
return ""
23+
result = []
24+
self._inorder_traversal(root, result)
25+
return ",".join(map(str, result))
26+
27+
def _inorder_traversal(self, node, result):
28+
if node is None:
29+
return
30+
self._inorder_traversal(node.left, result)
31+
result.append(node.val)
32+
self._inorder_traversal(node.right, result)
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)