Java solution


  • 0

    Anyone can share me where to learn those fancy 1-liner, it looks interesting.

    public class Solution {
        public String complexNumberMultiply(String a, String b) {
            String[] A = a.split("\\+");
            String[] B = b.split("\\+");
            
            int a1 = Integer.parseInt(A[0]), a2 = Integer.parseInt(A[1].substring(0, A[1].length()-1));
            int b1 = Integer.parseInt(B[0]), b2 = Integer.parseInt(B[1].substring(0, B[1].length()-1));
            
            int ResA = a1 * b1 - a2 * b2;
            int ResB = a1 * b2 + a2 * b1;
            
            return "" + ResA + "+" + ResB + "i";
        }
    }
    

Log in to reply
 

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