Skip to content

Commit a34df7a

Browse files
committed
Runtime 34 ms (Top 38.68%) | Memory 13.0 MB (Top 56.1%)
1 parent c3144f9 commit a34df7a

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
class Solution:
22
def complexNumberMultiply(self, num1: str, num2: str) -> str:
3-
a1, b1 = num1[:-1].split("+")
4-
a2, b2 = num2[:-1].split("+")
5-
a1, b1, a2, b2 = int(a1), int(b1), int(a2), int(b2)
6-
real = a1*a2-b1*b2
7-
imaginary = a1*b2+a2*b1
8-
return str(real)+"+"+str(imaginary)+"i"
3+
i1=num1.index('+')
4+
i2=num2.index('+')
5+
a=int(num1[0:i1])
6+
x=int(num2[0:i2])
7+
b=int(num1[i1+1:len(num1)-1])
8+
y=int(num2[i2+1:len(num2)-1])
9+
ans1=a*x+(-1)*b*y
10+
ans2=a*y+b*x
11+
return str(ans1)+'+'+(str(ans2)+'i')

0 commit comments

Comments
 (0)