描写叙述:
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.思路:
简而言之,要实现的就是BigInteger(a).Multiply(BigInteger(b))的功能,但非常显然,leetcode中不让用BigInteger
代码:
public class Solution { public String multiply(String num1, String num2) { if(num1==null||num2==null) return new String(); num1=num1.trim(); num2=num2.trim(); if(num1.equals("0")||num2.equals("0")) return "0"; ListlistNum1=new ArrayList<>(); List listNum2=new ArrayList<>(); List listResult=new ArrayList<>(); int len1=num1.length(); int len2=num2.length(); int i=0,j=0,lenResult=0,index=0; int baseNum=0,flowNum=0,tempNum1=0,tempNum2=0; for( i=len1-1;i>=0;i--) listNum1.add(num1.charAt(i)-'0'); for( i=len2-1;i>=0;i--) listNum2.add(num2.charAt(i)-'0'); tempNum2=listNum2.get(0); for(i=0;i