Skip to content

Instantly share code, notes, and snippets.

@cixuuz
Created September 2, 2017 21:05
Show Gist options
  • Save cixuuz/09f1d677a6e3c21d6fa08262e48d9515 to your computer and use it in GitHub Desktop.
Save cixuuz/09f1d677a6e3c21d6fa08262e48d9515 to your computer and use it in GitHub Desktop.
[537. Complex Number Multiplication] #leetcode
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