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
For example:
1 -> A
2 -> B
3 -> C
...
26 -> Z
27 -> AA
28 -> AB
思路:依旧是进制转换类型的,由于不是从0开始的 我们人为把他调整为从0开始 0-25有26个数,也就是10进制转26进制
代码:
class Solution {
public:
string convertToTitle(int n) {
string s;
string temp;
int count=0;
while(n){
char ch;
n=n-1;
ch = 'A' + n%26;
temp.push_back(ch);
s.insert(0,temp);
n/=26;
temp.clear();
}
return s;
}
};
本文介绍了一种将正整数转换为Excel单元格标题的方法,通过实现从1到26进制转换,解决如何将数字映射为字母序列的问题。
971

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



