Merge pull request #1728 from Jack-Zhang-1314/patch-2

update 1047.删除字符串中的所有相邻重复项.md about rust
This commit is contained in:
程序员Carl
2022-11-14 09:45:19 +08:00
committed by GitHub

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"> <p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>