分析
26进制的问题。
需要注意每“位”都是从0开始,因此需要先对
n
n
n 减一。
代码
class Solution {
public:
string convertToTitle(int n) {
string res;
while (n--) {
res += n % 26 + 'A';
n /= 26;
}
reverse(res.begin(), res.end());
return res;
}
};