java.lang.Object
g0501_0600.s0537_complex_number_multiplication.Solution

public class Solution extends java.lang.Object
537 - Complex Number Multiplication.

Medium

A complex number can be represented as a string on the form "**real**+**imaginary**i" where:

  • real is the real part and is an integer in the range [-100, 100].
  • imaginary is the imaginary part and is an integer in the range [-100, 100].
  • i2 == -1.

Given two complex numbers num1 and num2 as strings, return a string of the complex number that represents their multiplications.

Example 1:

Input: num1 = “1+1i”, num2 = “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: num1 = “1+-1i”, num2 = “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.

Constraints:

  • num1 and num2 are valid complex numbers.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    java.lang.String
    complexNumberMultiply(java.lang.String num1, java.lang.String num2)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • complexNumberMultiply

      public java.lang.String complexNumberMultiply(java.lang.String num1, java.lang.String num2)