feat: 1047_remove_all_adjacent_duplicates_in_string

This commit is contained in:
SquidSpirit 2025-09-20 02:48:05 +08:00
parent 163aeafd47
commit b69b2b25a9
3 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "remove_all_adjacent_duplicates_in_string"
version = "0.1.0"

View File

@ -0,0 +1,6 @@
[package]
name = "remove_all_adjacent_duplicates_in_string"
version = "0.1.0"
edition = "2024"
[dependencies]

View File

@ -0,0 +1,17 @@
pub struct Solution;
impl Solution {
pub fn remove_duplicates(s: String) -> String {
let mut stack = String::new();
for c in s.bytes() {
if Some(c) == stack.bytes().last() {
stack.pop();
} else {
stack.push(c as char);
}
}
stack
}
}