原题
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
分析
不断的去模再计算,注意的是这里是从1开始,不是从0开始,所以要n-1
class Solution {
public:
string convertToTitle(int n) {
string tmp;
while(n)
{
tmp.push_back((n-1)%26+'A');
n=(n-1)/26;
}
string res(tmp.rbegin(),tmp.rend());
return res;
}
};