Easy to understand C Solution


  • 0
    A
    char *str = NULL;
    int i, remainder, size = 0;
    const int factor = 26;
    
    i = n;
    while (i-- > 0) {
        i /= factor;
        size++;   
    }
    
    str = (char *)malloc((size + 1) * sizeof(char));
    i = size;
    str[i--] = '\0';
    while (i >= 0) {
        remainder = --n % factor;
        str[i--] = 'A' + remainder;
        n /= factor;
    }
    
    return str;

Log in to reply
 

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