PackageSiweifasan_6_5;ImportOrg.omg.CORBA.INTERNAL;/*** @Description: Given an array a[0,1,..., n-1], build an array b[0,1,..., n-1], where the elements in B b[i]=a[0]*a[1]*...*a[i-1]*a[i+1]*...*a[ N-1]. You cannot use division. * @Author: Allen * @Return:*/ Public classMain03 { Public Static voidMain (string[] args) {int[] A = {1,2,3,4,5}; Solution03 SLT=NewSolution03 (); int[] B =slt.multiply (A); for(inti=0; i<b.length; i++) {System.out.print (B[i]+" "); } }}classSolution03 { Public int[] Multiply (int[] A) {int[] B =New int[A.length]; b[0]=1; for(intI=1; i < b.length; i++) {B[i]=b[i-1]*a[i-1]; } intTemp=1; for(intJ=a.length-2; j>=0; j--) {Temp*= a[j+1]; B[J]*=temp; } returnB; }}
Interview Question 66: Given an array a[0,1,..., n-1], build an array b[0,1,..., n-1], where the elements in B b[i]=a[0]*a[1]*...*a[i-1]*a[i+1]*...*a[n-1]. You cannot use division.