My c solution in 19ms


  • -10
    C


    char *link(char *s1,char *s2)
    {
    int len1=strlen(s1);
    int len2=strlen(s2);
    for(int i=len1;i<len1+len2;i++)
    s1[i]=s2[i-len1];
    return s1;
    }

    char *integerToRoman(int x)
    {
    char *arr[13]={"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
    int value[13]= {1000,900,500,400,100,90,50,40,10,9,5,4,1};
    char roman=(char)malloc(sizeof(char)*100);
    memset(roman,0,100);
    for(int i=0;x!=0;i++)
    {
    while(x>=value[i])
    {
    x-=value[i];
    roman=link(roman,arr[i]);
    }
    }
    return roman;
    }


Log in to reply
 

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