【LeetCode】【字符串】题号:*537. 复数乘法

every blog every motto: You will never know unless you try

0. 前言

生活好难,再坚持坚持!

1. 字符串

在这里插入图片描述

1.1 题目

在这里插入图片描述

1.2

class Solution:
    def complexNumberMultiply(self, num1: str, num2: str) -> str:
        s1, v1 = num1.split('+')
        s2, v2 = num2.split('+')
        # print(s1, type(s1))
        # 实部
        s = int(s1) * int(s2) - int(v1[:-1]) * int(v2[:-1])
        # 虚部
        v = int(s1) * int(v2[:-1]) + int(s2) * int(v1[:-1])
        v = str(v) + 'i'

        sv = str(s) + '+' + v

        return sv

1.3

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_39190382/article/details/119393869