Given numbers represented as strings, return multiplication of the numbers as a string.
Note:the numbers can be arbitrarily large and is non-negative.
Problem solving idea One:
biginteger!!! The Java implementation is as follows:
static public string Multiply (string num1, String num2) { Java.math.BigInteger bi1=java.math.biginteger.valueof (0) ; for (int i=0;i<num1.length (); i++) { bi1=bi1.multiply (java.math.BigInteger.valueOf); Bi1=bi1.add (Java.math.BigInteger.valueOf (Num1.charat (i)-' 0 ')); Java.math.BigInteger bi2=java.math.biginteger.valueof (0); for (int i=0;i<num2.length (); i++) { bi2=bi2.multiply (java.math.BigInteger.valueOf); Bi2=bi2.add (Java.math.BigInteger.valueOf (Num2.charat (i)-' 0 ')); Return bi1.multiply (BI2). toString (); }
Ms Accepted, it is important to note that the system does not automatically import the math package, need to be added when declaring, but the use of BigInteger always have a cheat bright
Java for Leetcode 043 Multiply Strings