43. Multiply Strings

Posted 东方春

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了43. Multiply Strings相关的知识,希望对你有一定的参考价值。

/**
 * @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;
		};
		
		

  

以上是关于43. Multiply Strings的主要内容,如果未能解决你的问题,请参考以下文章

43. Multiply Strings

#Leetcode# 43. Multiply Strings

Leetcode 43. Multiply Strings

43. Multiply Strings

43. Multiply Strings

LeetCode 43. Multiply Strings