Given a positive integer, return its corresponding column title as appear in an Excel sheet.
For example:
1 -> A
2 -> B
3 -> C
...
26 -> Z
27 -> AA
28 -> AB
class Solution {
public:
string convertToTitle(int n) {
string res = "";
if (n<1) {
return "";
}
while (n) {
n--;
char c = n%26 + 'A';
res += c;
n = n/26;
}
reverse(res.begin(),res.end());
return res;
}
};
本文介绍了一种将正整数转换为Excel单元格标题的方法,包括从1到26的映射规则,以及对应的实现代码。

被折叠的 条评论
为什么被折叠?



