# 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.

Source: Internet
Author: User

` 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.

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.