题目要求: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.
题目链接:leetCode
我的思路
两个数相乘的时候,最后得到的积位数绝对不会超过这两个数的位数和
假设A数有m位,B数有n位,两数相乘得到C的位数为m+n,那么使用m+n的int数组存放每一位相乘的结果,当然数组中的每一位都不一定是个位数,所以最后用一个循环把这个数组中的数字循环一边,逐个进位,最后得到结果
如果采用这种思路的话,自己就需要手动处理一些首位为0的情况
代码
代码是C++的:
class Solution
{
public:
string multiply(string num1, string num2)