问题:https://leetcode.com/problems/excel-sheet-column-title/?tab=Description
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
*分析:**10进制转26进制。但要先减1,避免出现整除的结果。因为52=2(26^1),就是B*,而不是正确结果AZ。
C++代码:
class Solution {
public:
string convertToTitle(int n) {
string res;
while(n!=0){
res.insert(res.begin(),'A'+(n-1)%26);
n=(n-1)/26;
}
return res;
}
};