my 0ms C solution,easy to understand


  • 0
    S
    char* convertToTitle(int n) {
    	char s[10] = { 0 };
    	int i = 0, j = 0;
    	while (n){
    		s[i++] = --n % 26 + 'A';
    		n = n / 26;
    	}
    	char *p = (char*)malloc((i+1)*sizeof(char));
    	while (i){
    		p[j++] = s[--i];
    	}
    	p[j] = '\0';
    	return p;
    }
    

Log in to reply
 

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