publicstaticvoidmain(String[] args){ Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); // 个数 LinkedList<Integer> items = new LinkedList<>(); for(int i = 0; i < n; i++){ items.offer(scanner.nextInt()); } int count = 0; // 计数
while (items.size() > 1){ int first = items.getFirst(); int end = items.getLast(); if(first == end){ // 首尾出队列 items.poll(); items.removeLast(); }else { int add = 0;