My java solution with BigInteger


  • -3
    A

    For this question, we can use Java BigInteger class, which can do all the work multiplying two strings for us.

    I know even if you know this solution in the interview, the interviewer may still require you to implement one by yourself. Anyway, just share this tip with all of you.

    My Solution:

    import java.math.BigInteger;
    
    public class Solution {
        public String multiply(String num1, String num2) {
            BigInteger a = new BigInteger(num1);
            BigInteger b = new BigInteger(num2);
            
            return a.multiply(b).toString();
        }
    }

  • 0
    C

    Aha , i write the same code as you...


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.