Skip to content

Commit a63ebbb

Browse files
authored
Added tasks 79-114
1 parent e191236 commit a63ebbb

File tree

21 files changed

+820
-0
lines changed

21 files changed

+820
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ Rust-based LeetCode algorithm problem solutions, regularly updated.
8888

8989
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
9090
|-|-|-|-|-|-
91+
| 0114 |[Flatten Binary Tree to Linked List](src/main/rust/g0101_0200/s0114_flatten_binary_tree_to_linked_list/Solution.rs)| Medium | Array, Hash_Table, Tree, Binary_Tree, Divide_and_Conquer, 2024_09_08_Time_0_ms_(100.00%)_Space_2.7_MB_(50.00%) | ug, | ug,
9192
| 0024 |[Swap Nodes in Pairs](src/main/rust/g0001_0100/s0024_swap_nodes_in_pairs/Solution.rs)| Medium | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
9293
| 0021 |[Merge Two Sorted Lists](src/main/rust/g0001_0100/s0021_merge_two_sorted_lists/Solution.rs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 0 | 100.00
9394
| 0025 |[Reverse Nodes in k-Group](src/main/rust/g0001_0100/s0025_reverse_nodes_in_k_group/Solution.rs)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(k) | 0 | 100.00
@@ -96,6 +97,10 @@ Rust-based LeetCode algorithm problem solutions, regularly updated.
9697

9798
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
9899
|-|-|-|-|-|-
100+
| 0094 |[Binary Tree Inorder Traversal](src/main/rust/g0001_0100/s0094_binary_tree_inorder_traversal/Solution.rs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Big_O_Time_O(n)_Space_O(n), 2024_09_08_Time_0_ms_(100.00%)_Space_2.2_MB_(33.33%) | ug, | ug,
101+
| 0102 |[Binary Tree Level Order Traversal](src/main/rust/g0101_0200/s0102_binary_tree_level_order_traversal/Solution.rs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N), 2024_09_08_Time_1_ms_(80.61%)_Space_2.4_MB_(24.49%) | ug, | ug,
102+
| 0104 |[Maximum Depth of Binary Tree](src/main/rust/g0101_0200/s0104_maximum_depth_of_binary_tree/Solution.rs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(H), 2024_09_08_Time_1_ms_(80.46%)_Space_2.7_MB_(50.19%) | ug, | ug,
103+
| 0098 |[Validate Binary Search Tree](src/main/rust/g0001_0100/s0098_validate_binary_search_tree/Solution.rs)| Medium | String, Dynamic_Programming | 1 | 77.46
99104

100105
#### Udemy Trie and Heap
101106

@@ -192,11 +197,15 @@ Rust-based LeetCode algorithm problem solutions, regularly updated.
192197

193198
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
194199
|-|-|-|-|-|-
200+
| 0094 |[Binary Tree Inorder Traversal](src/main/rust/g0001_0100/s0094_binary_tree_inorder_traversal/Solution.rs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Big_O_Time_O(n)_Space_O(n), 2024_09_08_Time_0_ms_(100.00%)_Space_2.2_MB_(33.33%) | ug, | ug,
195201

196202
#### Day 11 Tree
197203

198204
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
199205
|-|-|-|-|-|-
206+
| 0102 |[Binary Tree Level Order Traversal](src/main/rust/g0101_0200/s0102_binary_tree_level_order_traversal/Solution.rs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N), 2024_09_08_Time_1_ms_(80.61%)_Space_2.4_MB_(24.49%) | ug, | ug,
207+
| 0104 |[Maximum Depth of Binary Tree](src/main/rust/g0101_0200/s0104_maximum_depth_of_binary_tree/Solution.rs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(H), 2024_09_08_Time_1_ms_(80.46%)_Space_2.7_MB_(50.19%) | ug, | ug,
208+
| 0101 |[Symmetric Tree](src/main/rust/g0101_0200/s0101_symmetric_tree/Solution.rs)| 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)), 2024_09_08_Time_0_ms_(100.00%)_Space_2.2_MB_(78.98%) | ug, | ug,
200209

201210
#### Day 12 Tree
202211

@@ -212,6 +221,7 @@ Rust-based LeetCode algorithm problem solutions, regularly updated.
212221

213222
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
214223
|-|-|-|-|-|-
224+
| 0098 |[Validate Binary Search Tree](src/main/rust/g0001_0100/s0098_validate_binary_search_tree/Solution.rs)| Medium | String, Dynamic_Programming | 1 | 77.46
215225

216226
### Data Structure II
217227

@@ -298,6 +308,7 @@ Rust-based LeetCode algorithm problem solutions, regularly updated.
298308

299309
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
300310
|-|-|-|-|-|-
311+
| 0105 |[Construct Binary Tree from Preorder and Inorder Traversal](src/main/rust/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/Solution.rs)| 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), 2024_09_08_Time_2_ms_(84.72%)_Space_2.9_MB_(25.00%) | ug, | ug,
301312

302313
#### Day 16 Tree
303314

@@ -472,6 +483,7 @@ Rust-based LeetCode algorithm problem solutions, regularly updated.
472483
|-|-|-|-|-|-
473484
| 0017 |[Letter Combinations of a Phone Number](src/main/rust/g0001_0100/s0017_letter_combinations_of_a_phone_number/Solution.rs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 0 | 100.00
474485
| 0022 |[Generate Parentheses](src/main/rust/g0001_0100/s0022_generate_parentheses/Solution.rs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(2^n)_Space_O(n) | 1 | 83.92
486+
| 0079 |[Word Search](src/main/rust/g0001_0100/s0079_word_search/Solution.rs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Backtracking, Big_O_Time_O(4^(m\*n))_Space_O(m\*n) | 1 | 99.28
475487

476488
#### Day 12 Dynamic Programming
477489

@@ -757,6 +769,7 @@ Rust-based LeetCode algorithm problem solutions, regularly updated.
757769

758770
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
759771
|-|-|-|-|-|-
772+
| 0096 |[Unique Binary Search Trees](src/main/rust/g0001_0100/s0096_unique_binary_search_trees/Solution.rs)| Medium | Dynamic_Programming, Math, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
760773

761774
#### Day 12
762775

@@ -863,6 +876,7 @@ Rust-based LeetCode algorithm problem solutions, regularly updated.
863876

864877
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
865878
|-|-|-|-|-|-
879+
| 0104 |[Maximum Depth of Binary Tree](src/main/rust/g0101_0200/s0104_maximum_depth_of_binary_tree/Solution.rs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(H), 2024_09_08_Time_1_ms_(80.46%)_Space_2.7_MB_(50.19%) | ug, | ug,
866880

867881
#### Day 11 Containers and Libraries
868882

@@ -1135,6 +1149,7 @@ Rust-based LeetCode algorithm problem solutions, regularly updated.
11351149

11361150
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
11371151
|-|-|-|-|-|-
1152+
| 0102 |[Binary Tree Level Order Traversal](src/main/rust/g0101_0200/s0102_binary_tree_level_order_traversal/Solution.rs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N), 2024_09_08_Time_1_ms_(80.61%)_Space_2.4_MB_(24.49%) | ug, | ug,
11381153

11391154
#### Day 7 Binary Search
11401155

@@ -1145,6 +1160,7 @@ Rust-based LeetCode algorithm problem solutions, regularly updated.
11451160

11461161
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
11471162
|-|-|-|-|-|-
1163+
| 0098 |[Validate Binary Search Tree](src/main/rust/g0001_0100/s0098_validate_binary_search_tree/Solution.rs)| Medium | String, Dynamic_Programming | 1 | 77.46
11481164

11491165
#### Day 9 Graph/BFS/DFS
11501166

@@ -1265,6 +1281,7 @@ Rust-based LeetCode algorithm problem solutions, regularly updated.
12651281

12661282
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
12671283
|-|-|-|-|-|-
1284+
| 0101 |[Symmetric Tree](src/main/rust/g0101_0200/s0101_symmetric_tree/Solution.rs)| 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)), 2024_09_08_Time_0_ms_(100.00%)_Space_2.2_MB_(78.98%) | ug, | ug,
12681285

12691286
#### Day 16 Design
12701287

@@ -1298,6 +1315,16 @@ Rust-based LeetCode algorithm problem solutions, regularly updated.
12981315

12991316
| # | Title | Difficulty | Tag | Time, ms | Time, %
13001317
|------|----------------|-------------|-------------|----------|---------
1318+
| 0114 |[Flatten Binary Tree to Linked List](src/main/rust/g0101_0200/s0114_flatten_binary_tree_to_linked_list/Solution.rs)| Medium | Array, Hash_Table, Tree, Binary_Tree, Divide_and_Conquer, 2024_09_08_Time_0_ms_(100.00%)_Space_2.7_MB_(50.00%) | ug, | ug,
1319+
| 0105 |[Construct Binary Tree from Preorder and Inorder Traversal](src/main/rust/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/Solution.rs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Tree, Binary_Tree, Divide_and_Conquer, Data_Structure_II_Day_15_Tree, Big_O_Time_O(N)_Space_O(N), 2024_09_08_Time_2_ms_(84.72%)_Space_2.9_MB_(25.00%) | ug, | ug,
1320+
| 0104 |[Maximum Depth of Binary Tree](src/main/rust/g0101_0200/s0104_maximum_depth_of_binary_tree/Solution.rs)| 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, Big_O_Time_O(N)_Space_O(H), 2024_09_08_Time_1_ms_(80.46%)_Space_2.7_MB_(50.19%) | ug, | ug,
1321+
| 0102 |[Binary Tree Level Order Traversal](src/main/rust/g0101_0200/s0102_binary_tree_level_order_traversal/Solution.rs)| 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, Big_O_Time_O(N)_Space_O(N), 2024_09_08_Time_1_ms_(80.61%)_Space_2.4_MB_(24.49%) | ug, | ug,
1322+
| 0101 |[Symmetric Tree](src/main/rust/g0101_0200/s0101_symmetric_tree/Solution.rs)| 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, Big_O_Time_O(N)_Space_O(log(N)), 2024_09_08_Time_0_ms_(100.00%)_Space_2.2_MB_(78.98%) | ug, | ug,
1323+
| 0098 |[Validate Binary Search Tree](src/main/rust/g0001_0100/s0098_validate_binary_search_tree/Solution.rs)| Medium | String, Dynamic_Programming | 1 | 77.46
1324+
| 0096 |[Unique Binary Search Trees](src/main/rust/g0001_0100/s0096_unique_binary_search_trees/Solution.rs)| Medium | Dynamic_Programming, Math, Tree, Binary_Tree, Binary_Search_Tree, Dynamic_Programming_I_Day_11, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
1325+
| 0094 |[Binary Tree Inorder Traversal](src/main/rust/g0001_0100/s0094_binary_tree_inorder_traversal/Solution.rs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Data_Structure_I_Day_10_Tree, Udemy_Tree_Stack_Queue, Big_O_Time_O(n)_Space_O(n), 2024_09_08_Time_0_ms_(100.00%)_Space_2.2_MB_(33.33%) | ug, | ug,
1326+
| 0084 |[Largest Rectangle in Histogram](src/main/rust/g0001_0100/s0084_largest_rectangle_in_histogram/Solution.rs)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Stack, Monotonic_Stack, Big_O_Time_O(n_log_n)_Space_O(log_n) | 7 | 92.48
1327+
| 0079 |[Word Search](src/main/rust/g0001_0100/s0079_word_search/Solution.rs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Backtracking, Algorithm_II_Day_11_Recursion_Backtracking, Big_O_Time_O(4^(m\*n))_Space_O(m\*n) | 1 | 99.28
13011328
| 0078 |[Subsets](src/main/rust/g0001_0100/s0078_subsets/Solution.rs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Backtracking, Algorithm_II_Day_9_Recursion_Backtracking, Udemy_Backtracking/Recursion, Big_O_Time_O(2^n)_Space_O(n\*2^n) | 0 | 100.00
13021329
| 0076 |[Minimum Window Substring](src/main/rust/g0001_0100/s0076_minimum_window_substring/Solution.rs)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Level_2_Day_14_Sliding_Window/Two_Pointer, Big_O_Time_O(s.length())_Space_O(1) | 0 | 100.00
13031330
| 0075 |[Sort Colors](src/main/rust/g0001_0100/s0075_sort_colors/Solution.rs)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Data_Structure_II_Day_2_Array, Udemy_Arrays, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Matrix #Backtracking
2+
// #Algorithm_II_Day_11_Recursion_Backtracking #Big_O_Time_O(4^(m*n))_Space_O(m*n)
3+
// #2024_09_08_Time_1_ms_(99.28%)_Space_2.1_MB_(93.53%)
4+
5+
impl Solution {
6+
pub fn exist(mut board: Vec<Vec<char>>, word: String) -> bool {
7+
let mut word = Vec::from_iter(word.chars());
8+
let mut map = [0; 58]; //A-65 z-122
9+
for i in 0..board.len() {
10+
for j in 0..board[0].len() {
11+
map[(board[i][j] as u8 - 65) as usize] += 1;
12+
}
13+
}
14+
15+
for c in &word {
16+
if map[(*c as u8 - 65) as usize] == 0 {
17+
return false;
18+
}
19+
}
20+
21+
if map[(word[0] as u8 - 65) as usize] > map[(word[word.len() - 1] as u8 - 65) as usize] {
22+
word.reverse();
23+
}
24+
25+
for i in 0..board.len() {
26+
for j in 0..board[0].len() {
27+
if board[i][j] != word[0] {
28+
continue;
29+
}
30+
let mut p = 0;
31+
let (mut k, mut l) = (i, j);
32+
let mut dir = vec![-1; word.len() - 1];
33+
loop {
34+
if p == word.len() - 1 {
35+
return true;
36+
}
37+
if dir[p] == -1 {
38+
board[k][l] = ' ';
39+
dir[p] = 0;
40+
if k > 0 && board[k - 1][l] == word[p + 1] {
41+
p += 1;
42+
k -= 1;
43+
continue;
44+
}
45+
}
46+
if dir[p] == 0 {
47+
dir[p] = 1;
48+
if l < board[k].len() - 1 && board[k][l + 1] == word[p + 1] {
49+
p += 1;
50+
l += 1;
51+
continue;
52+
}
53+
}
54+
if dir[p] == 1 {
55+
dir[p] = 2;
56+
if k < board.len() - 1 && board[k + 1][l] == word[p + 1] {
57+
p += 1;
58+
k += 1;
59+
continue;
60+
}
61+
}
62+
if dir[p] == 2 {
63+
dir[p] = 3;
64+
if l > 0 && board[k][l - 1] == word[p + 1] {
65+
p += 1;
66+
l -= 1;
67+
continue;
68+
}
69+
}
70+
while p > 0 && dir[p] == 3 {
71+
board[k][l] = word[p];
72+
dir[p] = -1;
73+
p -= 1;
74+
if dir[p] == 0 {
75+
k += 1;
76+
continue;
77+
}
78+
if dir[p] == 1 {
79+
l -= 1;
80+
continue;
81+
}
82+
if dir[p] == 2 {
83+
k -= 1;
84+
continue;
85+
}
86+
if dir[p] == 3 {
87+
l += 1;
88+
continue;
89+
}
90+
}
91+
if p == 0 && dir[p] == 3 {
92+
board[k][l] = word[p];
93+
break;
94+
}
95+
}
96+
}
97+
}
98+
false
99+
}
100+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
79\. Word Search
2+
3+
Medium
4+
5+
Given an `m x n` grid of characters `board` and a string `word`, return `true` _if_ `word` _exists in the grid_.
6+
7+
The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once.
8+
9+
**Example 1:**
10+
11+
![](https://assets.leetcode.com/uploads/2020/11/04/word2.jpg)
12+
13+
**Input:** board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCCED"
14+
15+
**Output:** true
16+
17+
**Example 2:**
18+
19+
![](https://assets.leetcode.com/uploads/2020/11/04/word-1.jpg)
20+
21+
**Input:** board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "SEE"
22+
23+
**Output:** true
24+
25+
**Example 3:**
26+
27+
![](https://assets.leetcode.com/uploads/2020/10/15/word3.jpg)
28+
29+
**Input:** board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCB"
30+
31+
**Output:** false
32+
33+
**Constraints:**
34+
35+
* `m == board.length`
36+
* `n = board[i].length`
37+
* `1 <= m, n <= 6`
38+
* `1 <= word.length <= 15`
39+
* `board` and `word` consists of only lowercase and uppercase English letters.
40+
41+
**Follow up:** Could you use search pruning to make your solution faster with a larger `board`?
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Array #Stack #Monotonic_Stack
2+
// #Big_O_Time_O(n_log_n)_Space_O(log_n) #2024_09_08_Time_7_ms_(92.48%)_Space_3.2_MB_(96.24%)
3+
4+
impl Solution {
5+
pub fn largest_rectangle_area(heights: Vec<i32>) -> i32 {
6+
Self::largest_area(&heights, 0, heights.len())
7+
}
8+
9+
fn largest_area(heights: &[i32], start: usize, limit: usize) -> i32 {
10+
if heights.is_empty() || start == limit {
11+
return 0;
12+
}
13+
if limit - start == 1 {
14+
return heights[start];
15+
}
16+
if limit - start == 2 {
17+
let max_of_two_bars = heights[start].max(heights[start + 1]);
18+
let area_from_two = heights[start].min(heights[start + 1]) * 2;
19+
return max_of_two_bars.max(area_from_two);
20+
}
21+
if Self::check_if_sorted(heights, start, limit) {
22+
let mut max_when_sorted = 0;
23+
for i in start..limit {
24+
max_when_sorted = max_when_sorted.max(heights[i] * (limit - i) as i32);
25+
}
26+
return max_when_sorted;
27+
} else {
28+
let min_ind = Self::find_min_in_array(heights, start, limit);
29+
return Self::max_of_three_nums(
30+
Self::largest_area(heights, start, min_ind),
31+
heights[min_ind] * (limit - start) as i32,
32+
Self::largest_area(heights, min_ind + 1, limit),
33+
);
34+
}
35+
}
36+
37+
fn find_min_in_array(heights: &[i32], start: usize, limit: usize) -> usize {
38+
let mut min = i32::MAX;
39+
let mut min_index = 0;
40+
for i in start..limit {
41+
if heights[i] < min {
42+
min = heights[i];
43+
min_index = i;
44+
}
45+
}
46+
min_index
47+
}
48+
49+
fn check_if_sorted(heights: &[i32], start: usize, limit: usize) -> bool {
50+
for i in start + 1..limit {
51+
if heights[i] < heights[i - 1] {
52+
return false;
53+
}
54+
}
55+
true
56+
}
57+
58+
fn max_of_three_nums(a: i32, b: i32, c: i32) -> i32 {
59+
a.max(b).max(c)
60+
}
61+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
84\. Largest Rectangle in Histogram
2+
3+
Hard
4+
5+
Given an array of integers `heights` representing the histogram's bar height where the width of each bar is `1`, return _the area of the largest rectangle in the histogram_.
6+
7+
**Example 1:**
8+
9+
![](https://assets.leetcode.com/uploads/2021/01/04/histogram.jpg)
10+
11+
**Input:** heights = [2,1,5,6,2,3]
12+
13+
**Output:** 10
14+
15+
**Explanation:** The above is a histogram where width of each bar is 1.
16+
17+
The largest rectangle is shown in the red area, which has an area = 10 units.
18+
19+
**Example 2:**
20+
21+
![](https://assets.leetcode.com/uploads/2021/01/04/histogram-1.jpg)
22+
23+
**Input:** heights = [2,4]
24+
25+
**Output:** 4
26+
27+
**Constraints:**
28+
29+
* <code>1 <= heights.length <= 10<sup>5</sup></code>
30+
* <code>0 <= heights[i] <= 10<sup>4</sup></code>

0 commit comments

Comments
 (0)