Java 6ms easy to understand solution


  • 0
    F
    public String complexNumberMultiply(String a, String b) {
    	int[] an = parseStr(a);
    	int[] bn = parseStr(b);
    	return (an[0] * bn[0] - an[1] * bn[1]) + "+"
    			+ (an[0] * bn[1] + an[1] * bn[0]) + "i";
    
    }
    
    private int[] parseStr(String s) {
    	int[] res = new int[2];
    	String[] strs = s.split("\\+");
    	res[0] = Integer.valueOf(strs[0]);
    	res[1] = Integer.valueOf(strs[1].substring(0, strs[1].length() - 1));
    	return res;
    }

Log in to reply
 

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