题目描述:

解题思路:

java代码:

 public class LeetCode43 {
public static void main(String[] args) {
String num1="123";
String num2="45";
System.out.println(num1+"和"+num2+"相乘的结果是:"+new Solution().multiply(num1, num2));
}
} class Solution {
public String multiply(String num1, String num2) {
int len1=num1.length(),len2=num2.length();
int[] result=new int[len1+len2];
for(int i=len1-1;i>=0;i--){
for(int j=len2-1;j>=0;j--){
int mul=(num1.charAt(i)-'0')*(num2.charAt(j)-'0');
int p1=i+j,p2=i+j+1;
int sum=mul+result[p2]; result[p1]+=sum/10;
result[p2]=sum%10;
}
}
StringBuilder sb=new StringBuilder();
for(int e:result){
if(!(sb.length()==0&&e==0))//若最高位是0,去除
sb.append(e);
}
return sb.length()==0?"0":sb.toString();
}
}

测试结果:

【LeetCode43】 Multiply Strings的更多相关文章

  1. 【leetcode】Multiply Strings

    Multiply Strings Given two numbers represented as strings, return multiplication of the numbers as a ...

  2. 【leetcode】Multiply Strings(middle)

    Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...

  3. 【Leetcode】【Medium】Multiply Strings

    Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...

  4. 【LeetCode练习题】Multiply Strings

    Multiply Strings Given two numbers represented as strings, return multiplication of the numbers as a ...

  5. 【POJ2406】 Power Strings (KMP)

    Power Strings Description Given two strings a and b we define a*b to be their concatenation. For exa ...

  6. 【POJ2406】【KMP】Power Strings

    Description Given two strings a and b we define a*b to be their concatenation. For example, if a = & ...

  7. 【LeetCode415】Add Strings

    题目描述: 解决思路: 此题较简单,和前面[LeetCode67]方法一样. Java代码: public class LeetCode415 { public static void main(St ...

  8. 【hash】Power Strings

    [题意]: 给出s串出来,能否找到一个前缀 ,通过多次前缀进行拼接.构成s串.如果有多个,请输出最多次数那个. 如:aaaa 可以用1个a,进行4次拼接 可以用2个a,进行2次拼接 可以用4个a,进行 ...

  9. 【LeetCode每天一题】Multiply Strings(字符串乘法)

    Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and ...

随机推荐

  1. react组件直接在document上添加事件

    demo:比如组件里有个div写的框框,点击document body的背景色变红,点击div写的框框没效果 componentDidMount(){ document.onclick = this. ...

  2. cordova打包安卓或IOS应用

    1,先搞个java jdk.我先用的1.7版本的,用cordova打包的时候各种报错,应该是向下不兼容吧.又换了个1.8版本.装jdk一定要注意jdk跟jre不能都装在目标文件夹的根目录下,jdk跟j ...

  3. 自动补全Typeahead

    采用 Typeahead (Bootstrap-3-Typeahead-master) <script type="text/javascript" src="/j ...

  4. Spring Boot--02MVC设置

    package com.smartmap.sample.ch1.conf; import java.util.List; import javax.servlet.http.HttpServletRe ...

  5. git 错误error: failed to push some refs to

    今天使用VSCODE 学习node.js,  想在git上push代码 于是在git上建立了一个私有的长裤, 连接后push代码时提示如下错误: error: failed to push some ...

  6. 612.1.004 ALGS4 | Elementary Sorts - 基础排序算法

    sublime编辑器写代码,命令行编译 减少对ide的依赖//可以提示缺少什么依赖import 所有示例代码动手敲一遍 Graham's Scan是经典的计算几何算法 shffule 与 map-re ...

  7. frame shiro 授权及原理简述

    shiro 授权模式 shiro采用的是rbac授权模式rbac,基于角色的权限管理,谁扮演什么角色,被允许做什么事情. shiro 授权流程 shiro 授权方式 1.编程式 通过写if/else授 ...

  8. Pig数据类型

    基本类型 int.long.float.double.chararray.bytearray.datatime.boolean.biginteger.bigdecimal 复杂类型 map.tuple ...

  9. leetCode题解之Number of Lines To Write String

    1.题目描述 2.分析 使用一个map将字母和数字对应起来,方便后续使用. 3.代码 vector<int> numberOfLines(vector<int>& wi ...

  10. Oracle EBS 隐藏帮助-诊断-检查