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 = "";
while(n)
{
res = (char)('A' + (n-1)%26) + res;
n = (n-1) / 26;
}
return res;
}
};

本文介绍了一种将正整数转换为Excel工作表中对应列标题的算法实现。例如,1对应A,26对应Z,27对应AA等。通过使用C++编程语言并遵循特定的数学规则来完成这一转换。

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



