import java.util.ArrayList; public class Solution { public int[] multiply(int[] A) { if(A==null || A.length == 0){ return null; } int[] B = new int[A.length]; int temp = 0; for (int i = 0; i < A.length; i++) { int res = 1; for (int j = 0; j < A.length; j++) { if( i == j){ temp = A[j];//临时变量存储A[j]的值,避免数组值的改变 A[j] = 1; res *= A[j]; A[j] = temp; }else { res *= A[j]; } } B[i] = res; } return B; } }
原文:https://www.cnblogs.com/q-1993/p/10937831.html