Skip to content

Commit 3593142

Browse files
committed
43. Multiply Strings
1 parent 1e61b1a commit 3593142

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

src/leetcode/_43_/Main.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package leetcode._43_;
2+
3+
/**
4+
* Created by zhangbo54 on 2019-03-04.
5+
*/
6+
public class Main {
7+
public static void main(String[] args) {
8+
Solution solution = new Solution();
9+
System.out.println(solution.multiply("123", "456"));
10+
}
11+
}
12+

src/leetcode/_43_/Solution.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package leetcode._43_;
2+
3+
import java.math.BigDecimal;
4+
5+
class Solution {
6+
public String multiply(String num1, String num2) {
7+
return new BigDecimal(num1).multiply(new BigDecimal(num2)).toString();
8+
}
9+
}

src/leetcode/_43_/solution.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
### [43\. Multiply StringsCopy for MarkdownCopy for Markdown](https://leetcode.com/problems/multiply-strings/)
2+
3+
Difficulty: **Medium**
4+
5+
6+
Given two non-negative integers `num1` and `num2` represented as strings, return the product of `num1` and `num2`, also represented as a string.
7+
8+
**Example 1:**
9+
10+
```
11+
Input: num1 = "2", num2 = "3"
12+
Output: "6"```
13+
14+
**Example 2:**
15+
16+
```
17+
Input: num1 = "123", num2 = "456"
18+
Output: "56088"
19+
```
20+
21+
**Note:**
22+
23+
1. The length of both `num1` and `num2` is < 110.
24+
2. Both `num1` and `num2` contain only digits `0-9`.
25+
3. Both `num1` and `num2` do not contain any leading zero, except the number 0 itself.
26+
4. You **must not use any built-in BigInteger library** or **convert the inputs to integer** directly.
27+
28+
29+
#### Solution
30+
31+
Language: **Java**
32+
33+
```java
34+
import java.math.BigDecimal;
35+
36+
class Solution {
37+
   public String multiply(String num1, String num2) {
38+
       return new BigDecimal(num1).multiply(new BigDecimal(num2)).toString();
39+
  }
40+
}
41+
```
42+
![](https://ws2.sinaimg.cn/large/006tKfTcgy1g1h7hkk2idj310m0oyjv9.jpg)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy