File tree 2 files changed +25
-0
lines changed
2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 427
427
529|[ Minesweeper] ( ./0529-minesweeper.js ) |Medium|
428
428
530|[ Minimum Absolute Difference in BST] ( ./0530-minimum-absolute-difference-in-bst.js ) |Easy|
429
429
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|
430
431
541|[ Reverse String II] ( ./0541-reverse-string-ii.js ) |Easy|
431
432
542|[ 01 Matrix] ( ./0542-01-matrix.js ) |Medium|
432
433
543|[ Diameter of Binary Tree] ( ./0543-diameter-of-binary-tree.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments