-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMultiply Strings
More file actions
27 lines (26 loc) · 847 Bytes
/
Multiply Strings
File metadata and controls
27 lines (26 loc) · 847 Bytes
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
class Solution:
def multiply(self, num1: str, num2: str) -> str:
ans=""
if(num1=='0' or num2=='0'):
ans="0"
return ans
else:
realans=0
for i in range(len(num1)-1,-1,-1):
carry=0
for j in range(len(num2)-1,-1,-1):
x=str(int(num1[i])*int(num2[j])+carry)
if(len(x)>1):
carry=int(x[0])
ans=x[1]+ans
else:
ans=x+ans
carry=0
if(carry>0):
ans=str(carry)+ans
carry=0
p=pow(10,len(num1)-1-i)
y=int(ans)*p
realans+=y
ans=''
return str(realans)