这个题最小的数字不是从0开始,而是从1开始。所以如果要用进制转换的思路来解决的话,在处理每一位的时候要把当前的位进行减1操作。
class Solution {
public:
string convertToTitle(int n) {
string res;
while(n)
{
n-=1;
int temp=n%26;
res+=(char)('A'+temp);
n/=26;
}
reverse(res.begin(),res.end());
return res;
}
};