mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
Merge pull request #1728 from Jack-Zhang-1314/patch-2
update 1047.删除字符串中的所有相邻重复项.md about rust
This commit is contained in:
@ -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"/>
|
||||
|
Reference in New Issue
Block a user