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 s;
while(n){
s = char(--n%26 + 'A') + s;
n /= 26;
}
return s;
}
};
本文介绍了一种将正整数转换为Excel工作表中对应列标题的算法实现。例如,数字1对应'A',26对应'Z',27对应'AA'等。该算法使用C++编程语言,并通过递减和模运算来确定每个位置上的字母。
972

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



