题解 | #点击消除#
点击消除
http://www.nowcoder.com/practice/8d3643ec29654cf8908b5cf3a0479fd5
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
char[] chrs = scan.nextLine().toCharArray();
StringBuffer ans = new StringBuffer("");
LinkedList<Character> ll = new LinkedList<>();
for (char chr : chrs) {
if (!ll.isEmpty() && ll.peekLast() == chr) {
ll.removeLast();
} else {
ll.add(chr);
}
}
while (!ll.isEmpty()) {
ans.append(ll.poll());
}
System.out.println("".equals(new String(ans)) ? 0 : ans);
}
}