Java Simple Solution


  • 0
    K
    public class Solution {
        public String complexNumberMultiply(String a, String b) {
            String num1[] = a.split("\\+");
            String num2[] = b.split("\\+");
    
            int integral = (Integer.parseInt(num1[0]) * Integer.parseInt(num2[0])) - (Integer.parseInt(num1[1].substring(0,num1[1].length() - 1)) * Integer.parseInt(num2[1].substring(0,num2[1].length() - 1)));
            int real = (Integer.parseInt(num1[0]) * Integer.parseInt(num2[1].substring(0,num2[1].length() - 1))) + (Integer.parseInt(num2[0]) * Integer.parseInt(num1[1].substring(0,num1[1].length() - 1)));
            
            return new String(integral+ "+" + real+"i");
            
        }
    }
    

Log in to reply
 

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