"topic" 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.
1 PackageCom.exe6.offer;2 3 /**4 * "title" given an array a[0,1,..., n-1], build an array b[0,1,..., n-1],5 * Where the elements in B b[i]=a[0]a[1] ... A[i-1]a[i+1] ... A[n-1]. 6 * Cannot use division. 7 * @authorWGS8 *9 */Ten Public classConstructmultiplearray { One A Public int[] Mutilyarray (int[] A) { - if(a==NULL|| a.length<=0)return NULL; - intlen=a.length; the int[] frontarray=New int[Len]; - if(len<=1)returnFrontarray; - int[] backarray=New int[Len]; -Frontarray[0]=backarray[len-1]=1; + - for(inti=1;i<len;i++){ +Frontarray[i]=frontarray[i-1]*a[i-1]; Abackarray[len-1-i]=backarray[len-i]*a[len-i]; at } - for(inti=0;i<len;i++){ -frontarray[i]=Backarray[i]; - } - returnFrontarray; - in } - Public Static voidMain (string[] args) { to int[] A=New int[]{1,2,3,4}; + int[] arr=NewConstructmultiplearray (). Mutilyarray (A); - for(intI:arr) { theSystem.out.print (i+ ""); * } $ Panax Notoginseng } - the}
Sword Point offer Series---build product array