Created
May 2, 2015 19:03
-
-
Save karlmutch/221e705051bb56e4cad0 to your computer and use it in GitHub Desktop.
This problem comes from a Google+ group and was described as * * You have an array of integers, and for each index you want to find the product of every integer except * the integer at that index. Write a function get_products_of_all_ints_except_at_index() that takes an * array of integers and returns an array of the products.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static BigInteger [] get_products_of_all_ints_except_at_index(BigInteger [] input) | |
{ | |
ArrayList<BigInteger> productResults = new ArrayList<BigInteger>(input.length); | |
BigInteger masterProduct = BigInteger.ONE; | |
for (BigInteger anItem : input) { | |
masterProduct = masterProduct.multiply(anItem); | |
} | |
for (BigInteger anItem : input) { | |
productResults.add(masterProduct.divide(anItem)); | |
} | |
return(productResults.toArray(new BigInteger[input.length])); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment