美文网首页
LeetCode每日一题:multiply strings

LeetCode每日一题:multiply strings

作者: yoshino | 来源:发表于2017-06-23 10:19 被阅读29次

    问题描述

    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.

    问题分析

    这题简直就是为java设计的,用C++的话还要考虑转化和进位,在java只需要用BigDecimal进行大数精确运算即可。

    代码实现

    public String multiply(String num1, String num2) {
            BigDecimal n1 = new BigDecimal(num1);
            BigDecimal n2 = new BigDecimal(num2);
            return n1.multiply(n2).toString();
        }
    

    相关文章

      网友评论

          本文标题:LeetCode每日一题:multiply strings

          本文链接:https://www.haomeiwen.com/subject/oxzqcxtx.html