题解 | #点击消除#

点击消除

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");
    }
}

全部评论

相关推荐

点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务