当前位置:网站首页>Multiple strings for leetcode topic resolution
Multiple strings for leetcode topic resolution
2022-06-23 06:02:00 【ruochen】
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 String multiply(String num1, String num2) {
if (num1 == null || num2 == null) {
return "";
}
int[] paper = new int[num1.length() + num2.length()];
char[] _num1 = num1.toCharArray();
char[] _num2 = num2.toCharArray();
for (int i = 0; i < _num1.length; i++) {
for (int j = 0; j < _num2.length; j++) {
paper[paper.length - (i + j + 2)] += (_num1[i] - '0')
* (_num2[j] - '0');
}
}
// add
for (int i = 0; i < paper.length - 1; i++) {
paper[i + 1] += paper[i] / 10;
paper[i] %= 10;
}
String s = "";
for (int i = paper.length - 1; i > 0; i--) {
if ("" == s && paper[i] == 0) {
continue;
}
s += paper[i];
}
s += paper[0];
return s;
}
// can't be accepted in leetcode
public String multiply2(String num1, String num2) {
if (num1 == null || num2 == null) {
return "";
}
BigInteger n1 = new BigInteger(num1);
BigInteger n2 = new BigInteger(num2);
return n1.multiply(n2).toString();
}边栏推荐
- matplotlib savefig多个图片叠加问题
- runc 符号链接挂载与容器逃逸漏洞预警(CVE-2021-30465)
- PAT 乙等 1023 组个最小数
- Analysis on the problems and causes of digital transformation of manufacturing industry
- Use of visdom
- Wireshark TS | video app cannot play
- [OWT] OWT client native P2P E2E test vs2017 build 6: modify script automatic generation vs Project
- Redis cache penetration solution - bloom filter
- Leetcode topic analysis: factorial training zeroes
- What is the magic of digital collections? Which reliable teams are currently developing
猜你喜欢

Kotlin Android simple activity jump, simple combination of handler and thread

jvm-05. garbage collection

Cloud native database is the future

How does win11 enable mobile hotspot? How to enable mobile hotspot in win11

ssm项目搭建

云原生数据库是未来

Memory analysis and memory leak detection

Redis cache penetration solution - bloom filter

【Cocos2d-x】截图分享功能

The digital collection market has just begun
随机推荐
三项最高级认证,两项创新技术、两大优秀案例,阿里云亮相云原生产业大会
Centos7 installation of postgresql8.2.15 and creation of stored procedures
【Cocos2d-x】可擦除的Layer:ErasableLayer
jvm-05.垃圾回收
Behind the hot digital collections, a strong technical team is needed to support the northern technical team
TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.3 全双工, 节能, 自动协商机制, 802.1X 流控制 / 3.3.3 链路层流量控制
True MySQL interview question (24) -- row column exchange
Pat class B 1020 Moon Cake
Jvm: when a method is overloaded, the specific method to call is determined by the static type of the incoming parameter rather than the actual type of the parameter
SQL表名与函数名相同导致SQL语句错误。
Pat class B 1019 C language
Pat class B 1013 C language
ssm项目搭建
Raspberry pie assert preliminary exercise
Excel sheet column number for leetcode topic resolution
PAT 乙等 1012 C语言
Digital collections - new investment opportunities
Real MySQL interview questions (XXVII) -- Classification of users by RFM analysis method
关于安装pip3 install chatterbot报错的问题
jvm-01.指令重排