Created
September 2, 2017 21:05
-
-
Save cixuuz/09f1d677a6e3c21d6fa08262e48d9515 to your computer and use it in GitHub Desktop.
[537. Complex Number Multiplication] #leetcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
// O(n) O(n) | |
public String complexNumberMultiply(String a, String b) { | |
int[] c = Stream.of((a+b).split("\\+|i")).mapToInt(Integer::parseInt).toArray(); | |
return (c[0]*c[2] - c[1]*c[3]) + "+" + (c[0]*c[3] + c[1]*c[2]) + "i"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment