This website contains ALL LeetCode **Premium** problems for
**FREE!!**.

All leaked interview problems are collected from Internet.

All leaked interview problems are collected from Internet.

Given two strings representing two complex numbers.

You need to return a string representing their multiplication. Note i^{2} = -1 according to the definition.

**Example 1:**

Input:"1+1i", "1+1i"Output:"0+2i"Explanation:(1 + i) * (1 + i) = 1 + i^{2}+ 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 + i^{2}- 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**.

b'

\n## Solution

\n

\n#### Approach #1 Simple Solution[Accepted]

\n

\n

'
\n\n

\n\n

**Algorithm**

Multiplication of two complex numbers can be done as:

\n\n\n

\nWe simply split up the real and the imaginary parts of the given complex strings based on the \'+\' and the \'i\' symbols. We store the real parts of the two strings and as and respectively and the imaginary parts as and respectively. Then, we multiply the real and the imaginary parts as required after converting the extracted parts into integers. Then, we again form the return string in the required format and return the result.

\n\n**Complexity Analysis**

- \n
- \n
Time complexity : . Here splitting takes constant time as length of the string is very small .

\n \n - \n
Space complexity : . Constant extra space is used.

\n \n

\n

Analysis written by: @vinod23

\n