思路:这类似一个特殊的26进制转换,1-26对应’A’-‘Z’,将其减1后,0-25对应‘A’-‘Z’;
代码:
class Solution {
public:
string convertToTitle(int n)
{
string res = "";
if(n==0)
return res;
int a = 0, b = 0;
while (n > 0)
{
--n;
a = n / 26; //商
b = n - a * 26; //余数
res.insert(0,1,'A'+b);
n = a;
}
return res;
}
};