-
Notifications
You must be signed in to change notification settings - Fork 0
/
43.py
32 lines (30 loc) · 943 Bytes
/
43.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
class Solution(object):
def multiply(self, num1, num2):
"""
:type num1: str
:type num2: str
:rtype: str
"""
if int(num1) == 0 or int(num2) == 0:
return 0
res_list = []
for i in range(len(num1) - 1, -1, -1):
res = int(num2) * int(num1[i])
res_list.insert(0, res)
next_num = 0
for i in range(len(res_list)-1,-1,-1):
if i == 0:
res_list[i] = str(res_list[i] + next_num)
break
res_list[i] = res_list[i] + next_num
if res_list[i]<10:
res_list[i] = str(res_list[i])
next_num = 0
continue
else:
num = res_list[i]%10
next_num = (res_list[i]-num)/10
res_list[i] = str(num)
return ''.join(res_list)
solu = Solution()
print solu.multiply('408','5')