题解 | #构建乘积数组#
构建乘积数组
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
int[] res = new int[A.length];
for(int i = 0; i < res.length;i++){
res[i] = 1;
}
for(int i = 0; i < A.length;i++){
for(int j = 0 ; j < res.length; j++){
if(i != j){
res[j] = res[j]*A[i];
}
}
}
return res;
}
}
#剑指OFFER#
查看13道真题和解析