Skip to content

Latest commit

 

History

History
20 lines (18 loc) · 605 Bytes

896.md

File metadata and controls

20 lines (18 loc) · 605 Bytes

896. Monotonic Array

Solution 1 (time O(n), space O(1))

class Solution(object):
    def complexNumberMultiply(self, num1, num2):
        """
        :type num1: str
        :type num2: str
        :rtype: str
        """
        num1 = num1.split("+")
        num2 = num2.split("+")
        num1_p1, num1_p2 = int(num1[0]), int(num1[1][:-1])
        num2_p1, num2_p2 = int(num2[0]), int(num2[1][:-1])
        ans_p1 = num1_p1 * num2_p1 - num1_p2 * num2_p2
        ans_p2 = num1_p1 * num2_p2 + num1_p2 * num2_p1
        return str(ans_p1) + "+" + str(ans_p2) + "i"