Skip to content

Commit d54b2b7

Browse files
authored
Create 537. Complex Number Multiplication.py
1 parent 813063e commit d54b2b7

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#
2+
3+
'''
4+
1. 아이디어 :
5+
i가 아닌부분(a), i인 부분(b)를 나눠서 계산
6+
7+
2. 시간복잡도 :
8+
O(1)
9+
10+
3. 자료구조/알고리즘 :
11+
-
12+
13+
'''
14+
class Solution:
15+
def complexNumberMultiply(self, num1: str, num2: str) -> str:
16+
17+
def parse_and_remove(num: str) -> list:
18+
num = num.split("+")
19+
num[0] = int(num[0])
20+
num[1] = int(num[1][:-1])
21+
return num
22+
23+
num1 = parse_and_remove(num1)
24+
num2 = parse_and_remove(num2)
25+
26+
not_i = num1[0] * num2[0] - num1[1] * num2[1]
27+
i = num1[0] * num2[1] + num1[1] * num2[0]
28+
29+
return str(not_i) + "+" + str(i) + "i"
30+
31+
32+

0 commit comments

Comments
 (0)