网易笔试题第二道java编程题

public class Main{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextInt()) {
int a = in.nextInt();
int[] b = new int[a];
for (int i = 0; i < b.length; i++) {
b[i] = in.nextInt();
}
Arrays.sort(b);
int max = b[0];
int min = b[0];
for (int i = 1; i < b.length; i++) {
max=b[i] + max;
if (max - min > 2) {
int mm = Arrays.binarySearch(b, min + 1);
if (!(mm >= 0)) {
System.out.println(min + 1);
break;
}
}

}
System.out.println(max + 1);

}

}
}

全部评论
public class Main3 { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextInt()) { int a = in.nextInt(); int[] b = new int[a]; for (int i = 0; i < b.length; i++) { b[i] = in.nextInt(); } Arrays.sort(b); int max = b[0]; int min = b[0]; for (int i = 1; i < b.length; i++) { max=b[i] + max; if (max - min > 2) { int mm = Arrays.binarySearch(b, min + 1); if (!(mm >= 0)) { System.out.println(min + 1); break; } }else { min=max; } } System.out.println(max + 1); } } }
点赞 回复 分享
发布于 2016-08-06 22:08
楼主,结果不对啊,AC了?
点赞 回复 分享
发布于 2016-08-06 21:49
最小数的那个?
点赞 回复 分享
发布于 2016-08-06 21:31

相关推荐

05-09 12:23
已编辑
华南理工大学 Java
野猪不是猪🐗:给他装的,双九+有实习的能看的上这种厂我直接吃⑨✌们拿它练练面试愣是给他整出幻觉了
点赞 评论 收藏
分享
06-17 21:57
门头沟学院 Java
白友:噗嗤,我发现有些人事就爱发这些,明明已读不回就行了,就是要恶心人
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务