写在最前面:一道很常规的字符串分割的题

leetcode【537】Complex Number Multiplication

Given two strings representing two complex numbers.

You need to return a string representing their multiplication. Note i2 = -1 according to the definition.

Example 1:

Input: "1+1i", "1+1i"
Output: "0+2i"
Explanation: (1 + i) * (1 + i) = 1 + i2 + 2 * i = 2i, and you need convert it to the form of 0+2i.

Example 2:

Input: "1+-1i", "1+-1i"
Output: "0+-2i"
Explanation: (1 - i) * (1 - i) = 1 + i2 - 2 * i = -2i, and you need convert it to the form of 0+-2i.

Note:

  1. The input strings will not have extra blank.
  2. The input strings will be given in the form of a+bi, where the integer a and b will both belong to the range of [-100, 100]. And the output should be also in this form.
class Solution(object):def complexNumberMultiply(self, a, b):""":type a: str:type b: str:rtype: str"""sub1 = int(a.split('+')[0]) *int( b.split('+')[0])sub2 = int(a.split('+')[0]) * int(b.split('+')[1][:-1])sub3 = int(a.split('+')[1][:-1]) * int(b.split('+')[0])sub4 = int(a.split('+')[1][:-1]) * int(b.split('+')[1][:-1])sum = sub1 + sub4*-1return str(sum) + '+'+str(sub2+sub3)+'i'

leetcode【537】Complex Number Multiplication(复数相乘)相关推荐

  1. Leetcode——537. Complex Number Multiplication

    题目原址 https://leetcode.com/problems/complex-number-multiplication/description/ 题目描述 Given two strings ...

  2. LeetCode 537. Complex Number Multiplication

    Given two strings representing two complex numbers. You need to return a string representing their m ...

  3. 【leetcode】537. Complex Number Multiplication(Python C++)

    537. Complex Number Multiplication 题目链接 537.1 题目描述: Given two strings representing two complex numbe ...

  4. [Swift]LeetCode537. 复数乘法 | Complex Number Multiplication

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ➤微信公众号:山青咏芝(shanqingyongzhi) ➤博客园地址:山青咏芝(https://www.cnblog ...

  5. 复数 Complex Number 教程

    复数 Complex Number 教程

  6. C++实现complex number复数的算法(附完整源码)

    C++实现complex number复数的算法 C++实现complex number复数的算法完整源码(定义,实现,main函数测试) C++实现complex number复数的算法完整源码(定 ...

  7. 创建一个复数类Complex,对复数进行数学运算

    参考,误抄袭 问题描述: 创建一个复数类Complex,对复数进行数学运算,复数具有如下格式:realPart+imaginaryPart*i,其中,i为-1的平方根,具体要求如下: (1)利用浮点变 ...

  8. java中两个复数相乘_用java实现复数的加减乘除运算

    用java实现复数的加减乘除运算 1. 背景 老师在课上布置了几道java编程题,此为其中之一 2. 题目内容 设计一个类Complex,用于封装对复数的下列操作: (1)一个带参数的构造函数,用于初 ...

  9. LeetCode:Largest Number - 求整型数组中各元素可拼合成的最大数字

    2019独角兽企业重金招聘Python工程师标准>>> 1.题目名称 Largest Number(求整型数组中各元素可拼合成的最大数字) 2.题目地址 https://leetco ...

最新文章

  1. 【NCEPU】吴丹飞:(CSAPP)计算机系统漫游
  2. Linux下Boost编译安装
  3. 创建数据源(ODBC)
  4. 《WinForm开发系列之控件篇》Item33 NotifyIcon(暂无)
  5. gc日志一般关注什么_Java架构师必懂的GC日志知识
  6. 调度场算法与逆波兰表达式
  7. 8种最有效的网站推广方案
  8. 【嵌入式系统】STM32串口通信的四种方法(基于RTOS)
  9. 七、区块链如何运用merkle tree验证交易真实性
  10. 猎豹浏览器小号窗口怎么打开 小号窗口打开方法简述
  11. 在Eclipse中使用CVS的实践建议
  12. xcom2.0_发布Xcom 2,Elliot Quest,Mesa图形库以及更多开放式游戏新闻
  13. 包教会一对一跟着CNS学单细胞测序(含空间转录组、chipseq、RNAseq、Atacseq 和外显子等)3月13日开始...
  14. SQL Server如何存储特殊字符、上标、下标
  15. Mac Brew Uninstall MySql
  16. UltraISO 软碟通注册码
  17. python qq群_用Python玩转QQ群论坛
  18. 【blender】基本操作总结-最常用的快捷键
  19. 误删除恢复 (extundelete)
  20. 慢慢整理一下用到的游戏相关工具

热门文章

  1. 5G融合行业专网解决方案分析与研究
  2. python程序化选股_GitHub - cat-steel/stock_pick: 这时一个通过设定选股条件来帮我们筛选股票的python程序...
  3. 【立创开发板】梁山派初体验
  4. docker 制作 jar 镜像
  5. 世界物联网排行榜: 华为第一、思科第二,物联网发展趋势该如何看?
  6. 2006中国企业500强名单
  7. 4076 字符串权值(模拟)
  8. 大数据助公交行业降成本提效率
  9. (C++)设计一个日期类Date,包括年、月、日等私有数据成员。要求实现日期的基本运算,包括某日期加上指定天数、某日期减去指定天数、两个日期相差的天数等。
  10. Firefox/Chrome下flash的wmode参数设为opaque或transparent时输入文本框中无法输入中文汉字的解决方法