求大佬看下8.14阿里面试第一题为什么我只能过20%。。。

看了下同学的python代码感觉思路都一样啊。。

代码如下:

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String nd = in.nextLine();
String[] ndStrs = nd.split(" ");
int n = Integer.parseInt(ndStrs[0]);
long d = Integer.parseInt(ndStrs[1]);
long[][] nn = new long[n][n];
long maxVal = Integer.MIN_VALUE;
for(int i = 0; i < n; i++) {
String nLine = in.nextLine();
String[] split = nLine.split(" ");
for (int j = 0;i<split.length;i++) {
nn[i][j] = Integer.parseInt(split[i]);
if(nn[i][j] > maxVal) {
maxVal = nn[i][j];
}
}
}
long step = 0;
boolean flag = false;
for(int i = 0;i< nn[0].length;i++) {
for(int j = 0;j < nn[0].length;j++) {
if((maxVal - nn[i][j]) % d == 0) {
step += (maxVal - nn[i][j]) / d;
} else {
flag = true;
break;
}
}
if(flag) break;
}
if(flag) {
System.out.println(-1);
} else {
System.out.println(step);
}
}
}


#阿里巴巴##笔试题目#
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-02 18:35
简历上把1个月实习写成了3个月,会进行背调吗?
码农索隆:一个月有一个月的实习经历,三个月有三个月的实习经历
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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