Leetcode no. 43
来源:互联网 发布:淘宝开店交税吗 编辑:程序博客网 时间:2024/05/18 22:17
43. 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.
- Converting the input string to integer is NOT allowed.
- You should NOT use internal library such as BigInteger.
public class Solution { public String multiply(String num1, String num2) { int[] res= new int[num1.length()+num2.length()]; for (int i = num1.length()-1; i >=0 ; i--) { for (int j = num2.length()-1; j >=0 ; j--) { int tmp= (num1.charAt(i)-'0')*(num2.charAt(j)-'0'); int sum= tmp+ res[i+j+1]; res[i+j]+= sum/10; res[i+j+1]= sum%10; } } StringBuilder sb= new StringBuilder(); for (int ele: res) { if (sb.length()!=0 || ele!=0) sb.append(ele); } return sb.length()==0 ? "0" : sb.toString(); }}
0 0
- Leetcode no. 43
- Leetcode NO.43 Multiply Strings
- LeetCode No.11 ~No.12
- Leetcode NO.78 Subsets
- Leetcode NO.77 Combinations
- Leetcode NO.46 Permutations
- 【leetcode】No. 235 LCABST
- LeetCode no. 35
- Leetcode no. 37
- Leetcode no. 279
- Leetcode no. 335
- Leetcode no. 283
- Leetcode no. 181 (sql)
- Leetcode no. 40
- Leetcode no. 238
- Leetcode no. 26
- Leetcode no. 80
- Leetcode no. 228
- c语言-常量变量笔记
- arcgis 卸载和注册表相关总结
- 修改maven本地仓库位置
- 正则表达式的基础和语法
- JavaScript公有、私有以及受保护的属性和方法
- Leetcode no. 43
- 视图的优点与缺点总结
- Java学习笔记之深入理解关键字null
- 余额宝
- String.split("|")问题
- canvas的常见用法
- 专题三 · 1022
- 当vector中存储的类型为指针时,vector.clear()的执行结果
- (转)Android侧滑菜单DrawerLayout的使用