Domanda di colloquio di Meta

Multiply two big ints.

Risposte di colloquio

Anonimo

30 apr 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

Anonimo

24 apr 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; }

Anonimo

30 apr 2015

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

1