Update 0844.比较含退格的字符串.md

This commit is contained in:
fw_qaq
2023-03-29 18:34:11 +08:00
committed by GitHub
parent 59c86a7023
commit e4951bc9db

View File

@ -565,7 +565,27 @@ impl Solution {
}
```
> 双栈法
```rust
impl Solution {
pub fn backspace_compare(s: String, t: String) -> bool {
Self::get_string(s) == Self::get_string(t)
}
pub fn get_string(string: String) -> String {
let mut s = String::new();
for c in string.chars() {
if c != '#' {
s.push(c);
} else if !s.is_empty() {
s.pop();
}
}
s
}
}
```
<p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank">