题目:
题解:
void reverse(char* str, int strSize) {
int left = 0, right = strSize - 1;
while (left < right) {
char tmp = str[left];
str[left] = str[right], str[right] = tmp;
left++;
right--;
}
}
char* convertToTitle(int columnNumber) {
char* ans = malloc(sizeof(char) * 8);
int ansSize = 0;
while (columnNumber > 0) {
--columnNumber;
ans[ansSize++] = columnNumber % 26 + 'A';
columnNumber /= 26;
}
ans[ansSize] = '\0';
reverse(ans, ansSize);
return ans;
}