|
|
back to boardI'm trying to use stack. It's true ! Why ? import java.util.Scanner; import java.util.Stack; public class CliperMessage_1654_Stack { public static void main(String[] arg1) { Scanner sc=new Scanner(System.in); StringBuilder sb=new StringBuilder(); Stack<Character> stc=new Stack<>(); sb.append(sc.nextLine()); if(sb.length()<=200000){ for(int i=0;i<sb.length();i++){ if(stc.isEmpty()||(stc.peek()!=sb.charAt(i))) stc.push(sb.charAt(i)); else if((stc.peek()==sb.charAt(i))) stc.pop();
}
StringBuilder sbn=new StringBuilder(); int j=0; while(!stc.empty()) sbn.insert(j++, ""+stc.pop()); System.out.println(sbn.reverse()); } } } |
|
|