0ms C language soltuion


  • 0
    N
    char* convertToTitle(int n) {
        if(!n) return NULL;
        char *result = malloc(8);
        result[7] = 0;
        int idx = 6, tmp;
        char GAP = 'A' - 1;
        while(n > 0)
        {
            tmp = n % 26;
            if(!tmp)
            {
                n -= 26;
                tmp = 26;
            }
            result[idx--] = tmp + GAP;
            n /= 26;
        }
        return result + idx + 1;
    }

Log in to reply
 

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