aboutsummaryrefslogtreecommitdiff
path: root/other/remove_adjacent_dup_str.rs
diff options
context:
space:
mode:
Diffstat (limited to 'other/remove_adjacent_dup_str.rs')
-rw-r--r--other/remove_adjacent_dup_str.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/other/remove_adjacent_dup_str.rs b/other/remove_adjacent_dup_str.rs
new file mode 100644
index 0000000..063cfbb
--- /dev/null
+++ b/other/remove_adjacent_dup_str.rs
@@ -0,0 +1,20 @@
+struct Solution;
+
+impl Solution {
+ pub fn remove_duplicates(s: String) -> String {
+ let mut ans = String::new();
+ for c in s.chars() {
+ if ans.len() > 0 && ans.chars().last() == Some(c) {
+ ans.pop();
+ } else {
+ ans.push(c);
+ }
+ }
+ ans
+ }
+}
+
+fn main() {
+ let s = "abbaca".to_string();
+ print!("{}", Solution::remove_duplicates(s));
+}