题目原址

https://leetcode.com/problems/complex-number-multiplication/description/

题目描述

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:
- The input strings will not have extra blank.
- 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.

解题思路

给定两个复数,求两个复数相×的结果。。这个题主要就是考察将给定的字符串按照指定符号分割

AC代码

class Solution {public String complexNumberMultiply(String a, String b) {String[] i1 = a.split("\\+");String[] ii1 = a.split("\\+")[1].split("i");String[] i2 = b.split("\\+");String[] ii2 = b.split("\\+")[1].split("i");int eqq1 = Integer.parseInt(i1[0]) * Integer.parseInt(i2[0]);int eqq2 = Integer.parseInt(i1[0]) * Integer.parseInt(ii2[0]);int eqq3 = Integer.parseInt(ii1[0]) * Integer.parseInt(i2[0]);int eqq4 = Integer.parseInt(ii1[0]) * Integer.parseInt(ii2[0]);int sum = eqq1 - eqq4;int e = eqq2 + eqq3;StringBuilder sb = new StringBuilder();sb.append(sum);sb.append('+');sb.append(e);sb.append("i");return sb.toString();}
}

Leetcode——537. Complex Number Multiplication相关推荐

  1. LeetCode 537. Complex Number Multiplication

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

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

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

  3. leetcode【537】Complex Number Multiplication(复数相乘)

    写在最前面:一道很常规的字符串分割的题 leetcode[537]Complex Number Multiplication Given two strings representing two co ...

  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. LeetCode:Largest Number - 求整型数组中各元素可拼合成的最大数字

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

  8. 【整数转字符串】LeetCode 9. Palindrome Number

    LeetCode 9. Palindrome Number Solution1: 不利用字符串 class Solution { public:bool isPalindrome(int x) {if ...

  9. 【To Do! 重点 正则表达式】LeetCode 65. Valid Number

    LeetCode 65. Valid Number 本博客转载自:[1]http://www.cnblogs.com/yuzhangcmu/p/4060348.html [2]https://blog ...

最新文章

  1. 你不知道的车牌识别系统
  2. AttributeError: ‘FPDF‘ object has no attribute ‘unifontsubset‘
  3. 程序员致富的若干方法探讨
  4. 【深入Java虚拟机JVM 10】回收方法区
  5. WebBrowser 操作(从网上收集)
  6. html5 自定义属性data-*
  7. 职场中不要问程序员这五类问题
  8. 搭建webUI自动化及问题解决:Message: ‘chromedriver‘ executable needs to be in PATH.解决办法
  9. 算法高级(13)-常见负载均衡算法Java代码实现
  10. 95-233-040-源码-TaskManager-TaskManager的jvm-exit-on-oom配置
  11. linux的memmap函数_究竟有多少linux内核命令行参数
  12. php创建目录规则,php创建目录功能
  13. h5页面判断安卓或ios点击下载App
  14. 大专计算机档案,大专档案自我鉴定(精选5篇)
  15. Java中动态代理实现原理深究
  16. 解决WiFi共享大师频繁掉线问题
  17. mysql中字符串汇总_Mysql中常见字符串处理函数汇总
  18. ubuntu检查端口是否开启_技术|使用 nc 命令检查远程端口是否打开
  19. ubuntu使用certbot给nginx添加ssl证书
  20. html文件右键没有打开方式,一个文件打不开,点右键,怎么在打开方式中加入Word,Excel的打开方式,打开方式中有Word的打开方式?...

热门文章

  1. 修改linux服务器nls_lang,Oracle下服务端字符集修改
  2. (十五)路过师大 - 4
  3. 高级技巧之vertical-align属性应用
  4. 信息学奥赛一本通1358 中缀表达式值(expr) ()
  5. request进行搜索引擎关键词提交
  6. House MD S4:Memorable quips
  7. 深度分析,皓丽M5_企业版_增强版共同点与核心区别?
  8. [JZOJ1901] 【2010集训队出题】光棱坦克
  9. 使用DecimalFormat进行数字的格式化
  10. kali linux通过ssh+putty来实现远程登录(亲测有效)