题解 | 点击消除

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char[] s = in.next().toCharArray();
        StringBuilder st = new StringBuilder();//StringBuilder此处可以用来模拟栈
        for(int i = 0;i<s.length;i++){//遍历数组
            char ch = s[i];
            if(st.length() != 0 && ch == st.charAt(st.length()-1)){
                //出栈
                st.deleteCharAt(st.length()-1);
            }
            else{
                //进栈
                st.append(ch);
            }
        }
        System.out.println(st.length() == 0 ? 0 : st.toString());
    
    }
}

全部评论

相关推荐

VirtualBool:都去逗他了?
点赞 评论 收藏
分享
真烦好烦真烦:豆包润色了自己没看看吗,再说了,都说豆包是愚蠢且勤快的大学生,ds才是聪明的研究生,怎么敢让豆包写论文的
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务