update 1047.删除字符串中的所有相邻重复项.md about rust
This commit is contained in:
parent
a4d54dd073
commit
309b49cf47
|
|
@ -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"/>
|
||||
|
|
|
|||
Loading…
Reference in New Issue