aboutsummaryrefslogtreecommitdiff
path: root/remove_adjacent_dup_str.rs
blob: 063cfbbda4c64387229c3bc33d56f84202e0aaa5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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));
}