标签:
/** * @param {string} num1 * @param {string} num2 * @return {string} */ var multiply = function(num1, num2) { num1 = num1.split("").reverse().join(""); num2 = num2.split("").reverse().join(""); var arr = new Array(); var push = 0; for(var loop2 = 0;loop2 < num2.length;loop2++){ for(var loop1 = 0;loop1 < num1.length;loop1++){ var temp = num2[loop2] * num1[loop1]; var curValue = arr[loop1 + loop2] ? arr[loop1 + loop2] : 0; curValue = Number(curValue) + Number(push) + Number(temp); push = parseInt(curValue / 10); arr[loop2 + loop1] = curValue % 10; } if(push){ arr[loop2 + loop1] = push; push = 0; } } arr = arr.reverse(); var rst = ""; for(var loop = 0;loop < arr.length;loop++){ if(!arr[loop] == 0 || !rst==‘‘){ rst += arr[loop]; } } if(rst==‘‘)return "0"; return rst; };
标签:
原文地址:http://www.cnblogs.com/dongfangchun/p/5615104.html