c solution with sscanf, snprintf, strdup.


  • 1
    B
    #define FORMAT "%d+%di"
    #define BUF_SIZE 128
    
    char* complexNumberMultiply(char* a, char* b) {
    	int a1, a2, b1, b2;
    	char buf[BUF_SIZE];
    	sscanf(a, FORMAT, &a1, &a2);
    	sscanf(b, FORMAT, &b1, &b2);
    	snprintf(buf, BUF_SIZE, FORMAT, a1 * b1 - a2 * b2, a1 * b2 + a2 * b1);
    	return strdup(buf);
    }
    

Log in to reply
 

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