笔试题:
1~100共一百个整数中有98个被放到了数组a[98]中。请写程序找出没有被放入数组的那2个数,并给出计算复杂度。
第一种方法:
public static void main(String[] args) {
//定义数组存放98个整数
int[] arry = new int[98];
Random r = new Random();
List<Integer> list = new ArrayList<>();
//随机产生98个1-100自然数(不重复)
while (list.size() < 98) {
int result = r.nextInt(100) + 1;
if (list.contains(result)) {
continue;
}
list.add(result);
}
//将98个数填充到数组中;
for (int i = 0; i < 98; i++) {