题解 | #点击消除# | Rust
点击消除
https://www.nowcoder.com/practice/8d3643ec29654cf8908b5cf3a0479fd5
use std::io::{self, *}; struct Solution {} impl Solution { pub fn clearStr(self, input: String) -> String { let mut ans = String::from(""); for c in input.chars() { if !ans.is_empty() && c == ans.as_bytes()[ans.len()-1] as char { ans.pop(); continue; } ans.push(c); } if ans.is_empty() { return String::from("0"); } return ans; } } fn main() { let mut input = String::new(); io::stdin().read_line(&mut input).unwrap(); let mut input = input.trim_end().to_string(); println!("{}", Solution{}.clearStr(input)); }