1ms c solution ?but need some extra space


  • 0
    F

    char *countAndSay(int n) {
    char s[5000]="1";
    int i=0,j=0,k=0,m;
    char say;
    char count='1';
    char res[5000];
    for (i=1;i<n;i++){
    j=0;k=0;
    while(s[j]!='\0'){
    say=s[j];
    if(s[j+1]==s[j]){
    count++;
    }
    else{
    res[k]=count;
    k++;
    res[k]=say;
    k++;
    count='1';
    }
    j++;
    } //while
    res[k]='\0';
    for(m=0;m<=k;m++)
    s[m]=res[m];
    }
    return s;
    }


Log in to reply
 

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