Python regex solution


  • 1
    		import re
    		pattern = '([-]?\d+)\+([-]?\d+)i'
    		match = re.search(pattern, a)
    		x,y = int(match.group(1)),int(match.group(2))
    		match = re.search(pattern, b)
    		m,n = int(match.group(1)),int(match.group(2))
    		return '%d+%di'%(x*m-y*n, y*m+x*n)
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.