[leetcode] Multiply Strings
Multiply Strings 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. Tags: math, string 字符串相乘,关键是模拟我们平时手算乘法时的过程。取出num2的每一位,乘以num1,再把之前得到的re向左移一位,再加上这个循环中的结果。所以我们需要实现两个函数multiplyNum(字符串乘以数字)和sum(两个字符串相加)。 num1或num2为零需要单独考虑,否则结果会出现类似0000的情况。 class Solution { public: string multiply(string num1, string num2) { int i = 0; string re; if(num1 == “0” […]