Given two numbers represented as strings, return multiplication of the numbers as a string.
Note: The numbers can be arbitrarily large and are non-negative.
Solution is trivial , multiple each digit of num2 to num1 and add all results up. Be careful of carries. Also a trick used here to speed up the code a little bit is to pre allocate the space for resulting number. The length of resulting number is no longer than num1.length()+num2.length(). Then the multiplication result of num1[i] and num2[j] should be put in result[i+j].
No comments:
Post a Comment