Merge branch 'youngyangyang04:master' into master

This commit is contained in:
roylx
2022-11-14 14:50:11 -07:00
committed by GitHub
2 changed files with 25 additions and 6 deletions

View File

@ -206,7 +206,7 @@ class Solution {
public int largestRectangleArea(int[] heights) {
int length = heights.length;
int[] minLeftIndex = new int [length];
int[] maxRigthIndex = new int [length];
int[] minRightIndex = new int [length];
// 记录左边第一个小于该柱子的下标
minLeftIndex[0] = -1 ;
for (int i = 1; i < length; i++) {
@ -215,17 +215,17 @@ class Solution {
while (t >= 0 && heights[t] >= heights[i]) t = minLeftIndex[t];
minLeftIndex[i] = t;
}
// 记录每个柱子 右边第一个小于该柱子的下标
maxRigthIndex[length - 1] = length;
// 记录每个柱子右边第一个小于该柱子的下标
minRightIndex[length - 1] = length;
for (int i = length - 2; i >= 0; i--) {
int t = i + 1;
while(t < length && heights[t] >= heights[i]) t = maxRigthIndex[t];
maxRigthIndex[i] = t;
while(t < length && heights[t] >= heights[i]) t = minRightIndex[t];
minRightIndex[i] = t;
}
// 求和
int result = 0;
for (int i = 0; i < length; i++) {
int sum = heights[i] * (maxRigthIndex[i] - minLeftIndex[i] - 1);
int sum = heights[i] * (minRightIndex[i] - minLeftIndex[i] - 1);
result = Math.max(sum, result);
}
return result;

View File

@ -447,6 +447,25 @@ object Solution {
}
```
rust:
```rust
impl Solution {
pub fn remove_duplicates(s: String) -> String {
let mut stack = vec![];
let mut chars: Vec<char> = s.chars().collect();
while let Some(c) = chars.pop() {
if stack.is_empty() || stack[stack.len() - 1] != c {
stack.push(c);
} else {
stack.pop();
}
}
stack.into_iter().rev().collect()
}
}
```
<p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>