-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultiply-strings.py
36 lines (32 loc) · 939 Bytes
/
multiply-strings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2
# also represented as a string.
# Note: You must not use any built-in BigInteger library or convert the inputs to integer directly.
class Solution(object):
def multiply(self, num1, num2):
"""
:type num1: str
:type num2: str
:rtype: str
"""
nums = {
'0': 0,
'1': 1,
'2': 2,
'3': 3,
'4': 4,
'5': 5,
'6': 6,
'7': 7,
'8': 8,
'9': 9,
'0':0
}
m = len(num1)
n = len(num2)
int_num1 = 0
int_num2= 0
for i in range(m):
int_num1 = int_num1 * 10 + nums[num1[i]]
for i in range(n):
int_num2 = int_num2 * 10 + nums[num2[i]]
return str(int_num1*int_num2)