leetcode-537.复数乘法
由于刚开始使用python,很不熟练,所决定边写题边学。
题目
示例
本题的难点是:
1)map
https://www.runoob.com/python/python-func-map.html
2)切片
https://www.jianshu.com/p/15715d6f4dad
我的解题方法:
class Solution:
def complexNumberMultiply(self, num1: str, num2: str) -> str:
real1,imag1 = map(int, num1[:-1].split('+'))
real2,imag2 = map(int, num2[:-1].split('+'))
real = real1*real2 - imag1*imag2
imag = real1*imag2 + imag1*real2
# print(real1,imag1,real2,imag2)
return str(real)+'+'+str(imag)+'i'