题解 | #构建乘积数组#
构建乘积数组
https://www.nowcoder.com/practice/94a4d381a68b47b7a8bed86f2975db46
import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param A int整型一维数组
* @return int整型一维数组
*/
public int[] multiply (int[] A) {
// write code here
if(A.length <= 1){
throw new RuntimeException("数组长度应该大于1");
}
int[] B = new int[A.length];
for(int i=0;i<B.length;i++){
int sum = 1;
for(int j =0;j<A.length;j++){
if(i == j)
continue;
sum *= A[j];
}
B[i] = sum;
}
return B;
}
}
科大讯飞公司氛围 477人发布
查看9道真题和解析