问题描述:
Given a positive integer, return its corresponding column title as appear in an Excel sheet.
示例:
1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB问题分析:
仔细观察会发现这是一个整除问题,稍作转化即可解决问题
过程详见代码:
class Solution {
public:
string convertToTitle(int n) {
string res = "";
while(n)
{
res.insert(res.begin(),(char)((n-1) % 26 + 'A'));
n = (n-1) / 26;
}
return res;
}
};