给定一个连续数组,找出缺失的数字
没什么好讲的,直接上代码吧。
public class FindLostNo{
public static void main(String[] args) {
Integer[] test1 = {10,11,12,13,14,16,17,19,20};
int[] test2 = null;
test2 = new int[11];
for(int i=10; i<(test2.length+8); i++) {
test2[test1[i-10]-10] = 1;
}
for(int i=0; i<test2.length; i++) {
if(test2[i]==0) {
System.out.println("The lost number is: " + (test2[i]+i+10));
}
}
}
}
运行输出如下:
The lost number is: 15
The lost number is: 18