feat: 1047_remove_all_adjacent_duplicates_in_string
This commit is contained in:
parent
163aeafd47
commit
b69b2b25a9
7
1047_remove_all_adjacent_duplicates_in_string/Cargo.lock
generated
Normal file
7
1047_remove_all_adjacent_duplicates_in_string/Cargo.lock
generated
Normal 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"
|
6
1047_remove_all_adjacent_duplicates_in_string/Cargo.toml
Normal file
6
1047_remove_all_adjacent_duplicates_in_string/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "remove_all_adjacent_duplicates_in_string"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
17
1047_remove_all_adjacent_duplicates_in_string/src/lib.rs
Normal file
17
1047_remove_all_adjacent_duplicates_in_string/src/lib.rs
Normal 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
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user