Skip to content

Commit e1933cb

Browse files
committedMar 5, 2025
Add solution #537
1 parent b300179 commit e1933cb

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@
427427
529|[Minesweeper](./0529-minesweeper.js)|Medium|
428428
530|[Minimum Absolute Difference in BST](./0530-minimum-absolute-difference-in-bst.js)|Easy|
429429
532|[K-diff Pairs in an Array](./0532-k-diff-pairs-in-an-array.js)|Medium|
430+
537|[Complex Number Multiplication](./0537-complex-number-multiplication.js)|Medium|
430431
541|[Reverse String II](./0541-reverse-string-ii.js)|Easy|
431432
542|[01 Matrix](./0542-01-matrix.js)|Medium|
432433
543|[Diameter of Binary Tree](./0543-diameter-of-binary-tree.js)|Easy|
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* 537. Complex Number Multiplication
3+
* https://leetcode.com/problems/complex-number-multiplication/
4+
* Difficulty: Medium
5+
*
6+
* A complex number can be represented as a string on the form "real+imaginaryi" where:
7+
* - real is the real part and is an integer in the range [-100, 100].
8+
* - imaginary is the imaginary part and is an integer in the range [-100, 100].
9+
* - i2 == -1.
10+
*
11+
* Given two complex numbers num1 and num2 as strings, return a string of the complex number
12+
* that represents their multiplications.
13+
*/
14+
15+
/**
16+
* @param {string} num1
17+
* @param {string} num2
18+
* @return {string}
19+
*/
20+
var complexNumberMultiply = function(num1, num2) {
21+
const [r1, i1] = num1.split('+').map(n => parseInt(n.replace('i', '')));
22+
const [r2, i2] = num2.split('+').map(n => parseInt(n.replace('i', '')));
23+
return `${r1 * r2 - i1 * i2}+${r1 * i2 + r2 * i1}i`;
24+
};

0 commit comments

Comments
 (0)
Please sign in to comment.