Question d’entretien chez Meta

Multiply two big ints.

Réponses aux questions d'entretien

Utilisateur anonyme

30 avr. 2015

The above code is neat; unfortunately, it does not account for *big* integers being multiplied. So, suppose we have two numbers that are close to the integer limit. What would happen when we try to multiple them? In addition, what happens when one of the integers is negative?

3

Utilisateur anonyme

24 avr. 2015

public static int bitwiseMultiply(int a, int b) { if (a == 0 || b == 0) { return 0; } if (a == 1) { return b; } else if (b == 1) { return a; } int result = 0; while (b >= 1) { if ((b & 1) == 1) { result = result + a; } a >= 1; } return result; }

Utilisateur anonyme

30 avr. 2015

Java Provides multiply() method for BigInteger datatype. It can be used directly.

1