题解 | #点击消除#
点击消除
https://www.nowcoder.com/practice/8d3643ec29654cf8908b5cf3a0479fd5
package main import ( "fmt" ) func main() { var s string; fmt.Scan(&s); stack := make([]rune,0); for _,ch := range s{ if len(stack) == 0 { stack = append(stack, ch); }else{ if ch == stack[len(stack)-1]{ stack = stack[:len(stack)-1]; }else{ stack = append(stack, ch); } } } s = ""; s = string(stack); if len(stack) != 0{ fmt.Println(s); }else{ fmt.Println("0"); } }