LeetCode-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.

public class Solution {
    public String multiply(String num1, String num2) {
        if(num1==null||num1.length()==0){
            return num2;
        }
        if(num2==null||num2.length()==0){
            return num1;
        }
        if(num1.length()==1&&Integer.parseInt(num1)==0){
            return "0";
        }
        if(num2.length()==1&&Integer.parseInt(num2)==0){
            return "0";
        }
        int[] numArray1=new int[num1.length()];
        int[] numArray2=new int[num2.length()];
        for(int i=0;i=0;index--){
                if(result[index]==0){
                    index--;
                    break;
                }
             }
        }
        for(int i=index;i>=0;i--){
            sb.append(result[i]);
        }
        return sb.toString();
    }
     
    private static int[] _multiply(int[] numArray1, int[] numArray2) {
        int[] result=new int[numArray1.length+numArray2.length];
        for(int i=0;i=10){
                result[i+1]+=result[i]/10;
                result[i]=result[i]%10;
            }
        }
        return result;
    }
 
}

 

你可能感兴趣的:(LeetCode)