构建乘积数组
构建乘积数组
http://www.nowcoder.com/questionTerminal/94a4d381a68b47b7a8bed86f2975db46
先将每个A[i]用temp值保存起来,再置为1进行相乘,赋给B[i]
时间复杂度为 O(n的二次方)
import java.util.ArrayList; public class Solution { public int[] multiply(int[] A) { int len = A.length; int[] B = new int[len]; int temp = 0; for(int i =0; i < len; i++){ temp = A[i]; A[i] = 1; B[i] = 1; for(int j = 0; j < A.length; j++){ B[i] *= A[j]; } A[i] = temp; } return B; } }