弱鸡题解:
- 将所有数据存到List
- 把数组sort一下
- 遍历取重复值和断值
- 样例全部跑通, 耗时1500ms
import java.util.*;
public class _1214_错误票据 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int line = scanner.nextInt();
scanner.nextLine();
List<Integer> list = new ArrayList<>();
for (int i = 0; i < line; i++) {
String[] strings = scanner.nextLine().split(" ");
for (String s: strings) {
list.add(Integer.parseInt(s));
}
}
Collections.sort(list);
//重复
int r = 0;
//连续
int k = 0;
for (int i = 0; i < list.size() - 1; i++) {
if (r > 0 && k > 0) {
break ;
}
int now = list.get(i);
int next = list.get(i + 1);
if (now == next) {
r = now;
}
if (now + 1 < next) {
k = now + 1;
}
}
System.out.println(k + " " + r);
}
}