删除字符串中的所有相邻重复项
Code
impl Solution {
pub fn remove_duplicates(s: String) -> String {
let mut stack: Vec<char> = Vec::new();
for c in s.chars() {
if stack.len() == 0 {
stack.push(c);
}else {
if c == stack[stack.len()-1]{
stack.pop();
}else{
stack.push(c);
}
}
}
stack.into_iter().collect::<String>()
}
}