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;
}
};